rich_engine 0.0.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: 37c9f68ab1fdc4951d70810a301758262203c270d81855259c04920194f44e21
4
+ data.tar.gz: f2848e8b2cfb1e99437aa99d4622f16e077b68e8866815192731b2f74160d9d2
5
+ SHA512:
6
+ metadata.gz: '01282dcff859e81e0cd7ac4ad4b266e450d317826e521f63603481d2c51a62ea4227582297db1abe26e1bfd05c8172e11f94706656a05e25552eb26009b4dad0'
7
+ data.tar.gz: 929a78668eff88fce37a81e2df06d310dd305b54000175423e0f032195c074cc1d64372cefde49ab3a8e79090d5c41ab6e84408d8c446ba789ce4ad213e7b70f
@@ -0,0 +1,28 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.6, 2.7, '3.0']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby ${{ matrix.ruby }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Build and test with Rake
23
+ run: |
24
+ gem install bundler
25
+ bundle install --jobs 4 --retry 3
26
+ bundle exec rake
27
+ - name: Linter
28
+ run: bundle exec standardrb
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ coverage/
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ format: progress
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem "standardrb"
9
+ gem "solargraph"
10
+ end
11
+
12
+ group :test do
13
+ gem "guard"
14
+ gem "guard-minitest", require: false
15
+ gem "minitest"
16
+ gem "minitest-focus"
17
+ gem "minitest-reporters"
18
+ gem "rake"
19
+ gem "simplecov", require: false
20
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,196 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rich_engine (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ ast (2.4.3)
11
+ backport (1.2.0)
12
+ benchmark (0.4.1)
13
+ builder (3.3.0)
14
+ coderay (1.1.3)
15
+ diff-lcs (1.6.2)
16
+ docile (1.4.1)
17
+ ffi (1.17.2-aarch64-linux-gnu)
18
+ ffi (1.17.2-aarch64-linux-musl)
19
+ ffi (1.17.2-arm-linux-gnu)
20
+ ffi (1.17.2-arm-linux-musl)
21
+ ffi (1.17.2-arm64-darwin)
22
+ ffi (1.17.2-x86_64-darwin)
23
+ ffi (1.17.2-x86_64-linux-gnu)
24
+ ffi (1.17.2-x86_64-linux-musl)
25
+ formatador (1.1.0)
26
+ guard (2.19.1)
27
+ formatador (>= 0.2.4)
28
+ listen (>= 2.7, < 4.0)
29
+ logger (~> 1.6)
30
+ lumberjack (>= 1.0.12, < 2.0)
31
+ nenv (~> 0.1)
32
+ notiffany (~> 0.0)
33
+ ostruct (~> 0.6)
34
+ pry (>= 0.13.0)
35
+ shellany (~> 0.0)
36
+ thor (>= 0.18.1)
37
+ guard-compat (1.2.1)
38
+ guard-minitest (2.4.6)
39
+ guard-compat (~> 1.2)
40
+ minitest (>= 3.0)
41
+ jaro_winkler (1.6.1)
42
+ json (2.12.2)
43
+ kramdown (2.5.1)
44
+ rexml (>= 3.3.9)
45
+ kramdown-parser-gfm (1.1.0)
46
+ kramdown (~> 2.0)
47
+ language_server-protocol (3.17.0.5)
48
+ lint_roller (1.1.0)
49
+ listen (3.9.0)
50
+ rb-fsevent (~> 0.10, >= 0.10.3)
51
+ rb-inotify (~> 0.9, >= 0.9.10)
52
+ logger (1.7.0)
53
+ lumberjack (1.2.10)
54
+ method_source (1.1.0)
55
+ minitest (5.25.5)
56
+ minitest-focus (1.4.0)
57
+ minitest (>= 4, < 6)
58
+ minitest-reporters (1.7.1)
59
+ ansi
60
+ builder
61
+ minitest (>= 5.0)
62
+ ruby-progressbar
63
+ nenv (0.3.0)
64
+ nokogiri (1.18.8-aarch64-linux-gnu)
65
+ racc (~> 1.4)
66
+ nokogiri (1.18.8-aarch64-linux-musl)
67
+ racc (~> 1.4)
68
+ nokogiri (1.18.8-arm-linux-gnu)
69
+ racc (~> 1.4)
70
+ nokogiri (1.18.8-arm-linux-musl)
71
+ racc (~> 1.4)
72
+ nokogiri (1.18.8-arm64-darwin)
73
+ racc (~> 1.4)
74
+ nokogiri (1.18.8-x86_64-darwin)
75
+ racc (~> 1.4)
76
+ nokogiri (1.18.8-x86_64-linux-gnu)
77
+ racc (~> 1.4)
78
+ nokogiri (1.18.8-x86_64-linux-musl)
79
+ racc (~> 1.4)
80
+ notiffany (0.1.3)
81
+ nenv (~> 0.1)
82
+ shellany (~> 0.0)
83
+ observer (0.1.2)
84
+ ostruct (0.6.1)
85
+ parallel (1.27.0)
86
+ parser (3.3.8.0)
87
+ ast (~> 2.4.1)
88
+ racc
89
+ prism (1.4.0)
90
+ pry (0.15.2)
91
+ coderay (~> 1.1)
92
+ method_source (~> 1.0)
93
+ racc (1.8.1)
94
+ rainbow (3.1.1)
95
+ rake (13.3.0)
96
+ rb-fsevent (0.11.2)
97
+ rb-inotify (0.11.1)
98
+ ffi (~> 1.0)
99
+ rbs (3.9.4)
100
+ logger
101
+ regexp_parser (2.10.0)
102
+ reverse_markdown (3.0.0)
103
+ nokogiri
104
+ rexml (3.4.1)
105
+ rubocop (1.75.8)
106
+ json (~> 2.3)
107
+ language_server-protocol (~> 3.17.0.2)
108
+ lint_roller (~> 1.1.0)
109
+ parallel (~> 1.10)
110
+ parser (>= 3.3.0.2)
111
+ rainbow (>= 2.2.2, < 4.0)
112
+ regexp_parser (>= 2.9.3, < 3.0)
113
+ rubocop-ast (>= 1.44.0, < 2.0)
114
+ ruby-progressbar (~> 1.7)
115
+ unicode-display_width (>= 2.4.0, < 4.0)
116
+ rubocop-ast (1.44.1)
117
+ parser (>= 3.3.7.2)
118
+ prism (~> 1.4)
119
+ rubocop-performance (1.25.0)
120
+ lint_roller (~> 1.1)
121
+ rubocop (>= 1.75.0, < 2.0)
122
+ rubocop-ast (>= 1.38.0, < 2.0)
123
+ ruby-progressbar (1.13.0)
124
+ shellany (0.0.1)
125
+ simplecov (0.22.0)
126
+ docile (~> 1.1)
127
+ simplecov-html (~> 0.11)
128
+ simplecov_json_formatter (~> 0.1)
129
+ simplecov-html (0.13.1)
130
+ simplecov_json_formatter (0.1.4)
131
+ solargraph (0.54.5)
132
+ backport (~> 1.2)
133
+ benchmark (~> 0.4)
134
+ bundler (~> 2.0)
135
+ diff-lcs (~> 1.4)
136
+ jaro_winkler (~> 1.6, >= 1.6.1)
137
+ kramdown (~> 2.3)
138
+ kramdown-parser-gfm (~> 1.1)
139
+ logger (~> 1.6)
140
+ observer (~> 0.1)
141
+ ostruct (~> 0.6)
142
+ parser (~> 3.0)
143
+ rbs (~> 3.3)
144
+ reverse_markdown (~> 3.0)
145
+ rubocop (~> 1.38)
146
+ thor (~> 1.0)
147
+ tilt (~> 2.0)
148
+ yard (~> 0.9, >= 0.9.24)
149
+ yard-solargraph (~> 0.1)
150
+ standard (1.50.0)
151
+ language_server-protocol (~> 3.17.0.2)
152
+ lint_roller (~> 1.0)
153
+ rubocop (~> 1.75.5)
154
+ standard-custom (~> 1.0.0)
155
+ standard-performance (~> 1.8)
156
+ standard-custom (1.0.2)
157
+ lint_roller (~> 1.0)
158
+ rubocop (~> 1.50)
159
+ standard-performance (1.8.0)
160
+ lint_roller (~> 1.1)
161
+ rubocop-performance (~> 1.25.0)
162
+ standardrb (1.0.1)
163
+ standard
164
+ thor (1.3.2)
165
+ tilt (2.6.0)
166
+ unicode-display_width (3.1.4)
167
+ unicode-emoji (~> 4.0, >= 4.0.4)
168
+ unicode-emoji (4.0.4)
169
+ yard (0.9.37)
170
+ yard-solargraph (0.1.0)
171
+ yard (~> 0.9)
172
+
173
+ PLATFORMS
174
+ aarch64-linux-gnu
175
+ aarch64-linux-musl
176
+ arm-linux-gnu
177
+ arm-linux-musl
178
+ arm64-darwin
179
+ x86_64-darwin
180
+ x86_64-linux-gnu
181
+ x86_64-linux-musl
182
+
183
+ DEPENDENCIES
184
+ guard
185
+ guard-minitest
186
+ minitest
187
+ minitest-focus
188
+ minitest-reporters
189
+ rake
190
+ rich_engine!
191
+ simplecov
192
+ solargraph
193
+ standardrb
194
+
195
+ BUNDLED WITH
196
+ 2.6.8
data/Guardfile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ guard :minitest do
21
+ # with Minitest::Unit
22
+ watch(%r{^test/(.*)/?(.*)\.rb$})
23
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
24
+ watch(%r{^test/test_helper\.rb$}) { "test" }
25
+ end
26
+
27
+ notification :off
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Matheus Richard
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,40 @@
1
+ # RichEngine
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rich_engine`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rich_engine'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rich_engine
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rich_engine.
36
+
37
+
38
+ ## License
39
+
40
+ 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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
13
+
14
+ task :guard do
15
+ system "bundle exec guard"
16
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rich_engine'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rich_engine"
4
+
5
+ class BgExample < RichEngine::Game
6
+ using RichEngine::StringColors
7
+
8
+ def on_create
9
+ @timer = RichEngine::Timer.new
10
+ @canvas.bg = RichEngine::UI::Textures.solid.blue
11
+ @clouds = 5.times.map { |i| Cloud.new(x: -(i + 1) * 20) }
12
+ @sun = Sun.new
13
+ end
14
+
15
+ def on_update(elapsed_time, key)
16
+ quit! if key == :q
17
+
18
+ @timer.update(elapsed_time)
19
+ @clouds.each { |cloud|
20
+ cloud.update(elapsed_time)
21
+
22
+ if cloud.x > @config[:screen_width]
23
+ @clouds.delete(cloud)
24
+ @clouds << Cloud.new
25
+ end
26
+ }
27
+
28
+ @canvas.clear
29
+
30
+ @sun.draw(@canvas)
31
+ @clouds.each { _1.draw(@canvas) }
32
+
33
+ draw_ground
34
+ end
35
+
36
+ def draw_ground
37
+ @canvas.draw_rect(
38
+ x: 0,
39
+ y: @config[:screen_height] - 1,
40
+ width: @config[:screen_width],
41
+ height: 1,
42
+ color: :black
43
+ )
44
+ end
45
+ end
46
+
47
+ class Sun
48
+ attr_accessor :x, :y
49
+
50
+ def initialize
51
+ @x = 0
52
+ @y = 0
53
+ end
54
+
55
+ def update(elapsed_time)
56
+ end
57
+
58
+ def draw(canvas)
59
+ canvas.draw_sprite(sprite, x: @x, y: @y, fg: :yellow)
60
+ end
61
+
62
+ def sprite
63
+ <<~SUN
64
+ ████
65
+ ████
66
+ SUN
67
+ end
68
+ end
69
+
70
+ class Cloud
71
+ attr_accessor :x, :y
72
+
73
+ def initialize(x: -rand(5..300))
74
+ @x = x
75
+ @y = rand(0..4)
76
+ @color = [:white, :bright_white].sample
77
+ @sprite = cloud_sprites.sample
78
+ @speed = rand(1..10)
79
+ end
80
+
81
+ def update(elapsed_time)
82
+ @x += elapsed_time * @speed
83
+ end
84
+
85
+ def draw(canvas)
86
+ canvas.draw_sprite(
87
+ @sprite,
88
+ x: @x,
89
+ y: @y,
90
+ fg: @color
91
+ )
92
+ end
93
+
94
+ def cloud_sprites
95
+ [
96
+ shape1,
97
+ shape2,
98
+ shape3,
99
+ shape4,
100
+ shape5
101
+ ]
102
+ end
103
+
104
+ def shape1
105
+ <<~CLOUD
106
+ ██
107
+ ██████
108
+ CLOUD
109
+ end
110
+
111
+ def shape2
112
+ <<~CLOUD
113
+ ███ ████
114
+ ██████████
115
+ CLOUD
116
+ end
117
+
118
+ def shape3
119
+ <<~CLOUD
120
+ ███
121
+ █████
122
+ CLOUD
123
+ end
124
+
125
+ def shape4
126
+ <<~CLOUD
127
+ ███
128
+ CLOUD
129
+ end
130
+
131
+ def shape5
132
+ <<~CLOUD
133
+ █████
134
+ CLOUD
135
+ end
136
+ end
137
+
138
+ BgExample.play
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rich_engine"
4
+
5
+ class GrainsOfSandExample < RichEngine::Game
6
+ using RichEngine::StringColors
7
+
8
+ def on_create
9
+ @canvas.bg = RichEngine::UI::Textures.solid.fg(:yellow)
10
+ @world = World.new(
11
+ grains_of_sand: [
12
+ GrainOfSand.new(x: @config[:screen_width] / 2 - rand(-10..10), y: -1),
13
+ GrainOfSand.new(x: @config[:screen_width] / 2, y: -@config[:screen_height] / 2)
14
+ ],
15
+ game_config: @config
16
+ )
17
+ end
18
+
19
+ def on_update(elapsed_time, key)
20
+ quit! if key == :q
21
+
22
+ @world.update(elapsed_time, key)
23
+
24
+ @canvas.clear
25
+
26
+ @world.draw(@canvas)
27
+ end
28
+ end
29
+
30
+ class World
31
+ def initialize(grains_of_sand:, game_config:)
32
+ @grains_of_sand = grains_of_sand
33
+ @game_config = game_config
34
+ @tiles = RichEngine::Matrix.new(width: width, height: height, fill_with: :empty)
35
+ @drop_timer = RichEngine::Timer.every(seconds: 0.05)
36
+ end
37
+
38
+ def update(elapsed_time, _key)
39
+ @drop_timer.update(elapsed_time)
40
+ @drop_timer.when_ready do
41
+ results = @grains_of_sand.map { |grain_of_sand|
42
+ next :not_moved if locked?(grain_of_sand)
43
+
44
+ if fits?(*grain_of_sand.try_move(:down).position)
45
+ grain_of_sand.move_down
46
+ :moved
47
+ elsif fits?(*grain_of_sand.try_move(:down).try_move(:left).position)
48
+ grain_of_sand.move_down.move_left
49
+ :moved
50
+ elsif fits?(*grain_of_sand.try_move(:down).try_move(:right).position)
51
+ grain_of_sand.move_down.move_right
52
+ :moved
53
+ else
54
+ lock_drop(grain_of_sand)
55
+ :not_moved
56
+ end
57
+ }
58
+
59
+ if results.none?(:moved)
60
+ raise RichEngine::Game::Exit
61
+ elsif has_available_space?
62
+ @grains_of_sand << GrainOfSand.new(x: (@game_config[:screen_width] / 2) + rand(-20..20), y: 0)
63
+ end
64
+ end
65
+ end
66
+
67
+ def draw(canvas)
68
+ @grains_of_sand.each { _1.draw(canvas) }
69
+ end
70
+
71
+ private
72
+
73
+ def locked?(grain_of_sand)
74
+ @tiles[grain_of_sand.x, grain_of_sand.y] == :filled
75
+ end
76
+
77
+ def fits?(x, y)
78
+ x >= 0 && x < width && y < height && @tiles[x, y] != :filled
79
+ end
80
+
81
+ def lock_drop(grain_of_sand)
82
+ @tiles[grain_of_sand.x, grain_of_sand.y] = :filled
83
+ end
84
+
85
+ def has_available_space?
86
+ @tiles.any? { |tile| tile == :empty }
87
+ end
88
+
89
+ def width
90
+ @game_config[:screen_width]
91
+ end
92
+
93
+ def height
94
+ @game_config[:screen_height]
95
+ end
96
+ end
97
+
98
+ class GrainOfSand
99
+ using RichEngine::StringColors
100
+
101
+ attr_reader :x, :y
102
+
103
+ def initialize(x:, y:)
104
+ @x = x
105
+ @y = y
106
+ end
107
+
108
+ def try_move(move)
109
+ copy = dup
110
+
111
+ if move == :down
112
+ copy.move_down
113
+ elsif move == :left
114
+ copy.move_left
115
+ elsif move == :right
116
+ copy.move_right
117
+ else
118
+ raise "Unknown move: #{move}"
119
+ end
120
+ end
121
+
122
+ def position
123
+ [@x, @y]
124
+ end
125
+
126
+ def move_down
127
+ @y += 1
128
+
129
+ self
130
+ end
131
+
132
+ def move_left
133
+ @x -= 1
134
+
135
+ self
136
+ end
137
+
138
+ def move_right
139
+ @x += 1
140
+
141
+ self
142
+ end
143
+
144
+ def draw(canvas)
145
+ canvas.write_string("•", x: @x, y: @y, fg: :black, bg: :yellow)
146
+ end
147
+ end
148
+
149
+ GrainsOfSandExample.play(width: 60, height: 20)
data/examples/noise.rb ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rich_engine"
4
+
5
+ class NoiseExample < RichEngine::Game
6
+ def on_create
7
+ @end_timer = RichEngine::Timer.new
8
+ @change_timer = RichEngine::Timer.every(seconds: 0.1)
9
+ end
10
+
11
+ def on_update(elapsed_time, key)
12
+ quit! if key == :q
13
+
14
+ @end_timer.update(elapsed_time)
15
+ @change_timer.update(elapsed_time)
16
+
17
+ @change_timer.when_ready do
18
+ @canvas.clear
19
+ @canvas.each_coord do |x, y|
20
+ @canvas[x, y] = RichEngine::Chance.of_one_in(2) ? "█" : " "
21
+ end
22
+ @canvas.write_string(elapsed_time, x: 1, y: 1)
23
+ end
24
+
25
+ quit! if @end_timer.get > 10
26
+ end
27
+ end
28
+
29
+ NoiseExample.play(width: 80, height: 40)