doomfire 0.1.0 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ed1e44013700ebc893171002841b1f5802e5a121d2a6d4d579bf20cacafc27c
4
- data.tar.gz: 837787f8b5e1181da8e48768578f6fc10bb4c19e326c9578adc6046df8e8eec8
3
+ metadata.gz: ecbc683e034fa23927451cf7792b1b234ad41d45681a1eb59d05759f44b65304
4
+ data.tar.gz: 7823ae5ad2eb86a5d090bd914193ae7c56c9b92b19b411457e6c3600884fd2fd
5
5
  SHA512:
6
- metadata.gz: 12ac8016527d22683f5d508f038bf6e73eab2b25965500f245ccfff200279cd87ec38ced3058ca1b268876fbae9f6b59ef69f8c4a426fc3997b158b29118aa63
7
- data.tar.gz: 609370538cc94a64411f39921b615d624cd22e4fe267a74d2229c8040dc8a409effb374a26b1b4eb3adfe5aab9f9aa4edf221f0b30376aa0b6e1d4476a5361cc
6
+ metadata.gz: 41592477937ec6d1fc954646117f9044c76714701eaa5a6784d509b6d70a12386afd84a25cc64db3840c4fd11dac6db82ec40c8637b8f01c67760e45b8a57eed
7
+ data.tar.gz: 59087d4f46cb35fb1146a33f42cd43638d08c690a7cc2dd45456aa364c97d1fe5c8d77bdc3b0041a44b2ed3252b78452d98d7aa30f9c10553b9d5eeb794866ef
data/.travis.yml CHANGED
@@ -3,5 +3,8 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
+ - 2.3.8
7
+ - 2.4.5
8
+ - 2.5.5
6
9
  - 2.6.2
7
10
  before_install: gem install bundler -v 2.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # 0.2.0
2
+
3
+ Terminal class now only works in the terminal and the new Spinner class should be used in the rake tasks. That should actually be a major version update to be honest but in 0.x versions I assume it's expected things can break.
4
+
5
+ - [x] Split Terminal class into `Base`, `Terminal` and `Spinner` classes
6
+ - [x] Started work on SDL version
7
+ - [x] Updated readme and example
8
+ - [x] Update tests
9
+
10
+ # 0.1.0
11
+
12
+ Works both in terminal as a command and in long running rake tasks as a spinner/progress bar indicator (not really).
13
+
14
+ - [x] Initial gem version published
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doomfire (0.1.0)
4
+ doomfire (0.2)
5
5
  paint
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Build Status](https://travis-ci.com/marcinruszkiewicz/doomfire.svg?branch=master)](https://travis-ci.com/marcinruszkiewicz/doomfire)
2
+ [![Gem Version](https://badge.fury.io/rb/doomfire.svg)](https://badge.fury.io/rb/doomfire)
3
+
1
4
  # Doomfire
2
5
 
3
6
  Put your terminal on fire.
@@ -39,7 +42,7 @@ require 'doomfire'
39
42
 
40
43
  desc 'some long running task'
41
44
  task :long do
42
- fire = Doomfire::Terminal.new
45
+ fire = Doomfire::Spinner.new
43
46
  fire.run
44
47
 
45
48
  5.times do
data/examples/long.rake CHANGED
@@ -2,7 +2,7 @@ require 'doomfire'
2
2
 
3
3
  desc 'some long running task'
4
4
  task :long do
5
- fire = Doomfire::Terminal.new
5
+ fire = Doomfire::Spinner.new
6
6
  fire.run
7
7
 
8
8
  5.times do
@@ -0,0 +1,57 @@
1
+ require 'fiddle'
2
+ require 'fiddle/import'
3
+ require 'pry'
4
+
5
+ module SDL
6
+ extend Fiddle::Importer
7
+
8
+ dlload 'libSDL2.dylib'
9
+
10
+ typealias 'Uint32', :int
11
+ typealias 'Uint16', :int
12
+ typealias 'Uint8', :int
13
+
14
+ SDL_INIT_VIDEO = 0x00000020
15
+ SDL_WINDOW_OPENGL = 0x00000000
16
+ SDL_WINDOWPOS_UNDEFINED = 0x1FFF0000 | 0
17
+ SDL_WINDOWPOS_CENTERED = 0x2FFF0000 | 0
18
+ SDL_QUIT = 0x100
19
+ SDL_KEYDOWN = 0x300
20
+ SDL_PIXELFORMAT_ARGB8888 = 0
21
+ SDL_TEXTUREACCESS_STATIC = 0
22
+
23
+ SDL_Event = union [
24
+ 'Uint32 type'
25
+ ]
26
+
27
+ extern 'int SDL_Init(Uint32 flags)'
28
+ extern 'void* SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)'
29
+ extern 'void* SDL_CreateRenderer(void* window, int index, Uint32 flags)'
30
+ extern 'void* SDL_CreateTexture(void* renderer, Uint32 format, int access, int w, int h)'
31
+ extern 'int SDL_WaitEvent(void* event)'
32
+ extern 'void SDL_Quit(void)'
33
+ extern 'void SDL_DestroyWindow(void* window)'
34
+ extern 'void SDL_DestroyRenderer(void* renderer)'
35
+ extern 'void SDL_DestroyTexture(void* texture)'
36
+ end
37
+
38
+ # https://dzone.com/articles/sdl2-pixel-drawing
39
+ # http://wiki.libsdl.org/SDL_Init
40
+ # https://github.com/davidsiaw/SDL2/blob/master/include/SDL_stdinc.h
41
+ # http://ruby-doc.org/stdlib-2.6.3/libdoc/fiddle/rdoc/Fiddle.html#method-c-dlopen
42
+ # https://www.honeybadger.io/blog/use-any-c-library-from-ruby-via-fiddle-the-ruby-standard-librarys-best-kept-secret/
43
+ # https://bitbucket.org/dandago/gigilabs/src/master/Sdl2PixelDrawing/Sdl2PixelDrawing/main.cpp
44
+
45
+ SDL.SDL_Init(SDL::SDL_INIT_VIDEO)
46
+ window = SDL.SDL_CreateWindow("Doomfire.rb", SDL::SDL_WINDOWPOS_UNDEFINED, SDL::SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL::SDL_WINDOW_OPENGL)
47
+ renderer = SDL.SDL_CreateRenderer(window, -1, 0)
48
+ texture = SDL.SDL_CreateTexture(renderer, SDL::SDL_PIXELFORMAT_ARGB8888, SDL::SDL_TEXTUREACCESS_STATIC, 640, 480)
49
+
50
+ event = SDL::SDL_Event.malloc
51
+ quit = false
52
+
53
+ until quit
54
+ SDL.SDL_WaitEvent(event)
55
+
56
+ quit = true if event.type == SDL::SDL_QUIT
57
+ end
data/exe/doomfire CHANGED
@@ -5,4 +5,4 @@ require 'rubygems'
5
5
  require 'bundler/setup'
6
6
  require 'doomfire'
7
7
 
8
- Doomfire::Terminal.new(blocking: true).run
8
+ Doomfire::Terminal.new.run
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doomfire
4
+ # Base class for the fire algorithm
5
+ class Base
6
+ RGB = [
7
+ [0, 0, 0],
8
+ [7, 7, 7],
9
+ [31, 7, 7],
10
+ [47, 15, 7],
11
+ [87, 23, 7],
12
+ [103, 31, 7],
13
+ [119, 31, 7],
14
+ [143, 39, 7],
15
+ [159, 47, 7],
16
+ [175, 63, 7],
17
+ [191, 71, 7],
18
+ [199, 71, 7],
19
+ [223, 79, 7],
20
+ [223, 87, 7],
21
+ [223, 87, 7],
22
+ [215, 103, 15],
23
+ [207, 111, 15],
24
+ [207, 119, 15],
25
+ [207, 127, 15],
26
+ [207, 135, 23],
27
+ [199, 135, 23],
28
+ [199, 143, 23],
29
+ [199, 151, 31],
30
+ [191, 159, 31],
31
+ [191, 159, 31],
32
+ [191, 167, 39],
33
+ [191, 167, 39],
34
+ [191, 175, 47],
35
+ [183, 175, 47],
36
+ [183, 183, 47],
37
+ [183, 183, 55],
38
+ [207, 207, 111],
39
+ [223, 223, 159],
40
+ [239, 239, 199],
41
+ [255, 255, 255]
42
+ ].freeze
43
+
44
+ FIRE_HEIGHT = 35
45
+
46
+ attr_reader :exit_requested, :pixels, :fire_width
47
+
48
+ def initialize
49
+ @counter = 0
50
+ @thread = nil
51
+ @exit_requested = false
52
+
53
+ prepare_output
54
+
55
+ initialize_pixels
56
+ end
57
+
58
+ def run
59
+ raise NotImplementedError
60
+ end
61
+
62
+ def stop
63
+ raise NotImplementedError
64
+ end
65
+
66
+ private
67
+
68
+ def spread_fire(src)
69
+ if @pixels[src].zero?
70
+ @pixels[src - @fire_width] = 1
71
+ else
72
+ random = rand(10).round & 3
73
+ dst = src - rand(3) + 1
74
+ @pixels[dst - @fire_width] = @pixels[src] - (random & 1)
75
+ end
76
+ end
77
+
78
+ def stop_fire
79
+ @pixels.pop(@fire_width)
80
+ @pixels.concat [].fill(0, 0, @fire_width)
81
+ end
82
+
83
+ def update_pixels
84
+ (1...FIRE_HEIGHT).to_a.reverse.each do |x|
85
+ (0...@fire_width).each do |y|
86
+ spread_fire(x * @fire_width + y)
87
+ end
88
+ end
89
+ end
90
+
91
+ def initialize_pixels
92
+ @pixels = []
93
+ last_line = @fire_width * (FIRE_HEIGHT - 1)
94
+ @pixels.fill(0, 0...last_line)
95
+ @pixels.fill(34, last_line..(last_line + @fire_width))
96
+ end
97
+
98
+ def prepare_output
99
+ @fire_width = 80
100
+ end
101
+
102
+ def fire_loop
103
+ raise NotImplementedError
104
+ end
105
+
106
+ def clear
107
+ raise NotImplementedError
108
+ end
109
+
110
+ def clear_screen
111
+ raise NotImplementedError
112
+ end
113
+
114
+ def print_pixels
115
+ raise NotImplementedError
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doomfire
4
+ # Same output as the Terminal class, but this runs in a separate thread,
5
+ # so the main process can continue with its work
6
+ class Spinner < Terminal
7
+ def run
8
+ @thread = Thread.start { fire_loop }
9
+ end
10
+
11
+ def stop
12
+ @exit_requested = true
13
+ @thread.join
14
+ end
15
+
16
+ private
17
+
18
+ def prepare_output
19
+ @fire_width = Doomfire::WindowSize.new.terminal_width
20
+ Paint.mode = 0xFFFFFF
21
+ clear_screen
22
+ end
23
+ end
24
+ end
@@ -3,68 +3,14 @@
3
3
  require 'paint'
4
4
 
5
5
  module Doomfire
6
- class Terminal
7
- RGB = [
8
- [0, 0, 0],
9
- [7, 7, 7],
10
- [31, 7, 7],
11
- [47, 15, 7],
12
- [87, 23, 7],
13
- [103, 31, 7],
14
- [119, 31, 7],
15
- [143, 39, 7],
16
- [159, 47, 7],
17
- [175, 63, 7],
18
- [191, 71, 7],
19
- [199, 71, 7],
20
- [223, 79, 7],
21
- [223, 87, 7],
22
- [223, 87, 7],
23
- [215, 103, 15],
24
- [207, 111, 15],
25
- [207, 119, 15],
26
- [207, 127, 15],
27
- [207, 135, 23],
28
- [199, 135, 23],
29
- [199, 143, 23],
30
- [199, 151, 31],
31
- [191, 159, 31],
32
- [191, 159, 31],
33
- [191, 167, 39],
34
- [191, 167, 39],
35
- [191, 175, 47],
36
- [183, 175, 47],
37
- [183, 183, 47],
38
- [183, 183, 55],
39
- [207, 207, 111],
40
- [223, 223, 159],
41
- [239, 239, 199],
42
- [255, 255, 255]
43
- ].freeze
44
-
45
- FIRE_HEIGHT = 35
46
-
47
- def initialize(blocking: false)
48
- @fire_width = Doomfire::WindowSize.new.terminal_width
49
- @exit_requested = false
50
- @counter = 0
51
- @blocking = blocking
52
- @thread = nil
53
-
54
- Paint.mode = 0xFFFFFF
55
- clear_screen
56
- initialize_pixels
57
-
58
- Kernel.trap('INT') { @exit_requested = true } if @blocking
59
- end
60
-
6
+ # This class outputs the pixels into the terminal, using ANSI color codes
7
+ class Terminal < Base
61
8
  def run
62
- @blocking ? fire_loop : @thread = Thread.start { fire_loop }
9
+ fire_loop
63
10
  end
64
11
 
65
12
  def stop
66
13
  @exit_requested = true
67
- @thread.join unless @blocking
68
14
  end
69
15
 
70
16
  private
@@ -86,19 +32,11 @@ module Doomfire
86
32
  clear_screen
87
33
  end
88
34
 
89
- def update_pixels
90
- (1...FIRE_HEIGHT).to_a.reverse.each do |x|
91
- (0...@fire_width).each do |y|
92
- spread_fire(x * @fire_width + y)
93
- end
94
- end
95
- end
96
-
97
- def initialize_pixels
98
- @pixels = []
99
- last_line = @fire_width * (FIRE_HEIGHT - 1)
100
- @pixels.fill(0, 0...last_line)
101
- @pixels.fill(34, last_line..(last_line + @fire_width))
35
+ def prepare_output
36
+ @fire_width = Doomfire::WindowSize.new.terminal_width
37
+ Paint.mode = 0xFFFFFF
38
+ Kernel.trap('INT') { @exit_requested = true }
39
+ clear_screen
102
40
  end
103
41
 
104
42
  def clear
@@ -119,20 +57,5 @@ module Doomfire
119
57
  puts "\e[2J"
120
58
  puts "\e[H"
121
59
  end
122
-
123
- def spread_fire(src)
124
- if @pixels[src].zero?
125
- @pixels[src - @fire_width] = 1
126
- else
127
- random = rand(10).round & 3
128
- dst = src - rand(3) + 1
129
- @pixels[dst - @fire_width] = @pixels[src] - (random & 1)
130
- end
131
- end
132
-
133
- def stop_fire
134
- @pixels.pop(@fire_width)
135
- @pixels.concat [].fill(0, 0, @fire_width)
136
- end
137
60
  end
138
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Doomfire
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2'
5
5
  end
data/lib/doomfire.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'doomfire/base'
3
4
  require 'doomfire/terminal'
5
+ require 'doomfire/spinner'
4
6
  require 'doomfire/version'
5
7
  require 'doomfire/window_size'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doomfire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Ruszkiewicz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-27 00:00:00.000000000 Z
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
@@ -91,6 +91,7 @@ files:
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
93
  - ".travis.yml"
94
+ - CHANGELOG.md
94
95
  - Gemfile
95
96
  - Gemfile.lock
96
97
  - LICENSE.txt
@@ -98,9 +99,12 @@ files:
98
99
  - Rakefile
99
100
  - doomfire.gemspec
100
101
  - examples/long.rake
102
+ - examples/sdl_test.rb
101
103
  - examples/terminal.png
102
104
  - exe/doomfire
103
105
  - lib/doomfire.rb
106
+ - lib/doomfire/base.rb
107
+ - lib/doomfire/spinner.rb
104
108
  - lib/doomfire/terminal.rb
105
109
  - lib/doomfire/version.rb
106
110
  - lib/doomfire/window_size.rb