doomfire 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ed1e44013700ebc893171002841b1f5802e5a121d2a6d4d579bf20cacafc27c
4
+ data.tar.gz: 837787f8b5e1181da8e48768578f6fc10bb4c19e326c9578adc6046df8e8eec8
5
+ SHA512:
6
+ metadata.gz: 12ac8016527d22683f5d508f038bf6e73eab2b25965500f245ccfff200279cd87ec38ced3058ca1b268876fbae9f6b59ef69f8c4a426fc3997b158b29118aa63
7
+ data.tar.gz: 609370538cc94a64411f39921b615d624cd22e4fe267a74d2229c8040dc8a409effb374a26b1b4eb3adfe5aab9f9aa4edf221f0b30376aa0b6e1d4476a5361cc
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ doomfire (0.1.0)
5
+ paint
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.2)
13
+ paint (2.1.0)
14
+ pry (0.12.2)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.3)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 2.0)
37
+ doomfire!
38
+ pry
39
+ rake (~> 10.0)
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Marcin Ruszkiewicz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Doomfire
2
+
3
+ Put your terminal on fire.
4
+
5
+ ![terminal example](examples/terminal.png)
6
+
7
+ This gem implements the [Doom fire algorithm](https://fabiensanglard.net/doom_fire_psx/) in Ruby, because why not, and outputs it into the terminal. Right now it requires the terminal to be able to display 24-bit colors, so it will either not work at all or not work properly on terminals that can't do that, for example on MacOS's default `Terminal.app` - in which case you should probably install a better terminal application (like [iTerm](https://www.iterm2.com) or whatever else you like).
8
+
9
+ You can check the list of terminals supporting 24-bit color [here](https://github.com/termstandard/colors).
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'doomfire'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install doomfire
26
+
27
+ ## Usage
28
+
29
+ The most basic way to run this is to run it directly from the command line:
30
+
31
+ $ doomfire
32
+
33
+ Pressing `CTRL`-`C` will stop the program gracefully after a few extra frames to let it end nicely.
34
+
35
+ Alternatively you can use it for amusement while running some long rake tasks.
36
+
37
+ ```ruby
38
+ require 'doomfire'
39
+
40
+ desc 'some long running task'
41
+ task :long do
42
+ fire = Doomfire::Terminal.new
43
+ fire.run
44
+
45
+ 5.times do
46
+ sleep 1
47
+ end
48
+
49
+ fire.stop
50
+ end
51
+ ```
52
+
53
+ This will run the fire in a separate thread while your rake tasks works in the main thread, and at the end of the task it will gracefully extinguish the fire and clear the terminal.
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcinruszkiewicz/doomfire.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ import 'examples/long.rake'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
data/doomfire.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'doomfire/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'doomfire'
9
+ spec.version = Doomfire::VERSION
10
+ spec.authors = ['Marcin Ruszkiewicz']
11
+ spec.email = ['marcin.ruszkiewicz@polcode.net']
12
+
13
+ spec.summary = 'Fire. In your console.'
14
+ spec.description = 'Puts your console on fire. Use a truecolor console for best effect.'
15
+ spec.homepage = 'https://github.com/marcinruszkiewicz/doomfire'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'paint'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 2.0'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'doomfire'
2
+
3
+ desc 'some long running task'
4
+ task :long do
5
+ fire = Doomfire::Terminal.new
6
+ fire.run
7
+
8
+ 5.times do
9
+ sleep 1
10
+ end
11
+
12
+ fire.stop
13
+ end
Binary file
data/exe/doomfire ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+ require 'doomfire'
7
+
8
+ Doomfire::Terminal.new(blocking: true).run
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'paint'
4
+
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
+
61
+ def run
62
+ @blocking ? fire_loop : @thread = Thread.start { fire_loop }
63
+ end
64
+
65
+ def stop
66
+ @exit_requested = true
67
+ @thread.join unless @blocking
68
+ end
69
+
70
+ private
71
+
72
+ def fire_loop
73
+ loop do
74
+ if @exit_requested
75
+ stop_fire if @counter.zero?
76
+ break if @counter == FIRE_HEIGHT
77
+
78
+ @counter += 1
79
+ end
80
+
81
+ update_pixels
82
+ clear
83
+ print_pixels
84
+ end
85
+
86
+ clear_screen
87
+ end
88
+
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))
102
+ end
103
+
104
+ def clear
105
+ sleep 0.05
106
+ puts "\e[34f\e[f"
107
+ end
108
+
109
+ def print_pixels
110
+ (0...FIRE_HEIGHT).each do |x|
111
+ (0...@fire_width).each do |y|
112
+ print Paint[' ', nil, RGB[@pixels[x * @fire_width + y]]]
113
+ end
114
+ puts
115
+ end
116
+ end
117
+
118
+ def clear_screen
119
+ puts "\e[2J"
120
+ puts "\e[H"
121
+ 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
+ end
138
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doomfire
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doomfire
4
+ class WindowSize
5
+ def terminal_width
6
+ return 80 unless unix?
7
+
8
+ result = dynamic_width
9
+ result < 20 ? 80 : result
10
+ rescue StandardError
11
+ 80
12
+ end
13
+
14
+ # rubocop:disable Lint/DuplicateMethods
15
+ begin
16
+ require 'io/console'
17
+
18
+ def dynamic_width
19
+ if IO.console
20
+ dynamic_width_via_io_object
21
+ else
22
+ dynamic_width_via_system_calls
23
+ end
24
+ end
25
+ rescue LoadError
26
+ def dynamic_width
27
+ dynamic_width_via_system_calls
28
+ end
29
+ end
30
+ # rubocop:enable Lint/DuplicateMethods
31
+
32
+ def dynamic_width_via_io_object
33
+ _rows, columns = IO.console.winsize
34
+ columns
35
+ end
36
+
37
+ def dynamic_width_via_system_calls
38
+ dynamic_width_stty.nonzero? || dynamic_width_tput
39
+ end
40
+
41
+ def dynamic_width_stty
42
+ `stty size 2>/dev/null`.split[1].to_i
43
+ end
44
+
45
+ def dynamic_width_tput
46
+ `tput cols 2>/dev/null`.to_i
47
+ end
48
+
49
+ def unix?
50
+ RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
51
+ end
52
+ end
53
+ end
data/lib/doomfire.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'doomfire/terminal'
4
+ require 'doomfire/version'
5
+ require 'doomfire/window_size'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doomfire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Ruszkiewicz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Puts your console on fire. Use a truecolor console for best effect.
84
+ email:
85
+ - marcin.ruszkiewicz@polcode.net
86
+ executables:
87
+ - doomfire
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - doomfire.gemspec
100
+ - examples/long.rake
101
+ - examples/terminal.png
102
+ - exe/doomfire
103
+ - lib/doomfire.rb
104
+ - lib/doomfire/terminal.rb
105
+ - lib/doomfire/version.rb
106
+ - lib/doomfire/window_size.rb
107
+ homepage: https://github.com/marcinruszkiewicz/doomfire
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Fire. In your console.
130
+ test_files: []