graphics 1.0.0b4 → 1.0.0b5

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
  SHA1:
3
- metadata.gz: 0dc93f577bc8db9cd0a1943285badd63a7a8b993
4
- data.tar.gz: c83fbd5e05b5a3e9294e5271f18e17310d7c122e
3
+ metadata.gz: 05606dab0e932b0e2a0244bfda441d75a5e075b4
4
+ data.tar.gz: adbefb635747458fed5734fd2464578390376a90
5
5
  SHA512:
6
- metadata.gz: a1a192627f226b8215af1e5b39bead9e16cf06c41937053e5cd2e627f6f35dff581b1d575356dea21f105f1aa46c3d49c26c3e42c9cd8906ea0eaaad50c13e58
7
- data.tar.gz: a22e5142715d85c7f1bd254b7ea478ad1ea185c110d7f93a0cfcc3537d8a6586210987ee7ecde9a842c40b66b64e70e75412aa30040e96b0064087de47088acb
6
+ metadata.gz: ec204d93283fd260d941d1851a2bd4425278754937f36a2495b84e7b319a0b4ee2455ac81b4dea3596819c5e7070add8f5c2e062fde7cacc66be2ce1b0ff31da
7
+ data.tar.gz: b55da059453df3ab0358cbc278567e3546d389e1811843bf34e30cb9c2ff1424f9a8afb20aabc090c3fdcd4b130e76731a6e35affa1f0dd2110db5893f80d329
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,23 @@
1
+ === 1.0.0b5 / 2015-10-31
2
+
3
+ * 10 minor enhancements:
4
+
5
+ * Added Simulation#add_keydown_handler.
6
+ * Added Simulation#keydown_handler, a hash of "key" -> block handlers.
7
+ * Added logging every N ticks for headless simulations or debugging.
8
+ * Switched all default key handlers to keydown handlers.
9
+ * add example: visualization of pi computation
10
+ * Improved key event handling.
11
+ * add example: visualization of pi computation
12
+ * Renamed rubysdl_setup to graphics_setup. rubysdl is out of the picture.
13
+ * Added example rainbow fluid simulation. (litonico)
14
+ * Added rainbows in greyscale, rgb-spectrum, and cubehelix. (litonico)
15
+
16
+ * 2 bug fixes:
17
+
18
+ * Fixed build issues with rubygems.
19
+ * Switched brew install to build universal packages so it can work with stock ruby.
20
+
1
21
  === 1.0.0b4 / 2015-09-14
2
22
 
3
23
  * 1 major enhancement:
@@ -44,8 +44,8 @@ class BounceSimulation < Graphics::Simulation
44
44
 
45
45
  def initialize_keys
46
46
  super
47
- add_key_handler :SPACE, &:randomize
48
- add_key_handler :R, &:reverse
47
+ add_keydown_handler " ", &:randomize
48
+ add_keydown_handler "r", &:reverse
49
49
  end
50
50
 
51
51
  def update n
@@ -66,12 +66,15 @@ class BounceSimulation < Graphics::Simulation
66
66
  end
67
67
 
68
68
  def reverse
69
- return if @guard
70
- @guard = true
71
69
  bs.each do |b|
72
70
  b.g *= -1
73
71
  end
74
- @guard = false
72
+ end
73
+
74
+ LOG_INTERVAL = 120
75
+
76
+ def log
77
+ puts bs.map(&:m).inject(&:+)
75
78
  end
76
79
  end
77
80
 
@@ -11,10 +11,10 @@ done
11
11
 
12
12
  # brew update
13
13
 
14
- brew install sdl
15
- brew install sdl_mixer --with-smpeg
16
- brew install sdl_ttf
17
- brew install sdl_image
14
+ brew install sdl --universal
15
+ brew install sdl_mixer --universal --with-smpeg
16
+ brew install sdl_ttf --universal
17
+ brew install sdl_image --universal --without-webp
18
18
 
19
19
  if [ -f $0 ]; then
20
20
  rake clean package
@@ -2,7 +2,7 @@
2
2
  # The top-level namespace.
3
3
 
4
4
  class Graphics
5
- VERSION = "1.0.0b4" # :nodoc:
5
+ VERSION = "1.0.0b5" # :nodoc:
6
6
  end
7
7
 
8
8
  require "graphics/simulation"
@@ -16,6 +16,9 @@ class Graphics::Simulation
16
16
  # radians to degrees
17
17
  R2D = 1 / D2R
18
18
 
19
+ # Call +log+ every N ticks, if +log+ is defined.
20
+ LOG_INTERVAL = 60
21
+
19
22
  # The window the simulation is drawing in.
20
23
  attr_accessor :screen
21
24
 
@@ -32,7 +35,6 @@ class Graphics::Simulation
32
35
  attr_accessor :font
33
36
 
34
37
  # A hash of color names to their values.
35
-
36
38
  attr_accessor :color
37
39
 
38
40
  # A hash of color values to their rgb values. For text, apparently. *shrug*
@@ -44,6 +46,9 @@ class Graphics::Simulation
44
46
  # Procs registered to handle key events.
45
47
  attr_accessor :key_handler
46
48
 
49
+ # Procs registered to handle keydown events.
50
+ attr_accessor :keydown_handler
51
+
47
52
  ##
48
53
  # Create a new simulation of a certain width and height. Optionally,
49
54
  # you can set the bits per pixel (0 for current screen settings),
@@ -70,6 +75,7 @@ class Graphics::Simulation
70
75
  self.iter_per_tick = 1
71
76
 
72
77
  self.key_handler = []
78
+ self.keydown_handler = {}
73
79
 
74
80
  initialize_keys
75
81
  initialize_colors
@@ -79,11 +85,11 @@ class Graphics::Simulation
79
85
  # Register default key events. Handles ESC & Q (quit) and P (pause).
80
86
 
81
87
  def initialize_keys
82
- add_key_handler(:ESCAPE) { exit }
83
- add_key_handler(:Q) { exit }
84
- add_key_handler(:P) { self.paused = !paused }
85
- add_key_handler(:SLASH) { self.iter_per_tick += 1 }
86
- add_key_handler(:MINUS) { self.iter_per_tick -= 1; self.iter_per_tick = 1 if iter_per_tick < 1 }
88
+ add_keydown_handler("\e") { exit }
89
+ add_keydown_handler("q") { exit }
90
+ add_keydown_handler("p") { self.paused = !paused }
91
+ add_keydown_handler("/") { self.iter_per_tick += 1 }
92
+ add_keydown_handler("-") { self.iter_per_tick -= 1; self.iter_per_tick = 1 if iter_per_tick < 1 }
87
93
  end
88
94
 
89
95
  def initialize_colors # :nodoc:
@@ -147,11 +153,20 @@ class Graphics::Simulation
147
153
  # won't be able to quit.
148
154
 
149
155
  def handle_event event, n
150
- exit if SDL::Event::Quit === event
156
+ case event
157
+ when SDL::Event::Quit then
158
+ exit
159
+ when SDL::Event::Keydown then
160
+ c = event.sym.chr rescue nil
161
+ b = keydown_handler[c]
162
+ b[self] if b
163
+ end
151
164
  end
152
165
 
153
166
  ##
154
- # Register a block to run for a particular key-press.
167
+ # Register a block to run for a particular key-press. This allows
168
+ # you to register multiple blocks for the same key and also to
169
+ # handle multiple keys down at the same time.
155
170
 
156
171
  def add_key_handler k, remove = nil, &b
157
172
  k = SDL::Key.const_get k
@@ -159,11 +174,20 @@ class Graphics::Simulation
159
174
  key_handler.unshift [k, b]
160
175
  end
161
176
 
177
+ ##
178
+ # Register a block to run for a particular keydown event. This is a
179
+ # single key handler per tick and only on a key-down event.
180
+
181
+ def add_keydown_handler k, &b
182
+ keydown_handler[k] = b
183
+ end
184
+
162
185
  ##
163
186
  # Handle key events by looking through key_handler and running any
164
187
  # blocks that match the key(s) being pressed.
165
188
 
166
189
  def handle_keys
190
+ SDL::Key.scan
167
191
  key_handler.each do |k, blk|
168
192
  blk[self] if SDL::Key.press? k
169
193
  end
@@ -180,15 +204,19 @@ class Graphics::Simulation
180
204
  n = 0
181
205
  event = nil
182
206
 
207
+ logger = respond_to? :log
208
+ log_interval = self.class::LOG_INTERVAL
209
+
183
210
  loop do
184
211
  handle_event event, n while event = SDL::Event.poll
185
- SDL::Key.scan
186
212
  handle_keys
187
213
 
188
214
  next if paused
189
215
 
190
216
  iter_per_tick.times { update n; n += 1 }
191
217
  draw_and_flip n
218
+
219
+ log if logger and n % log_interval == 0
192
220
  end
193
221
  end
194
222
 
@@ -437,6 +437,21 @@ class TestSimulation < Minitest::Test
437
437
  # end
438
438
  end
439
439
 
440
+ require 'graphics/rainbows'
441
+ class TestGraphics < Minitest::Test
442
+ def setup
443
+ @t = Graphics::Simulation.new 100, 100, 16, ""
444
+ end
445
+
446
+ def test_registering_rainbows
447
+ spectrum = Graphics::Hue.new
448
+ @t.initialize_rainbow spectrum, "spectrum"
449
+ assert_equal @t.color[:red], @t.color[:spectrum_0]
450
+ assert_equal @t.color[:green], @t.color[:spectrum_120]
451
+ assert_equal @t.color[:blue], @t.color[:spectrum_240]
452
+ end
453
+ end
454
+
440
455
  # class TestTrail < Minitest::Test
441
456
  # def test_draw
442
457
  # raise NotImplementedError, 'Need to write test_draw'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0b4
4
+ version: 1.0.0b5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBAjANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTE0MDkxNzIzMDcwN1oXDTE1MDkxNzIzMDcwN1owRTETMBEGA1UE
15
+ GRYDY29tMB4XDTE1MDkxOTIwNTEyMloXDTE2MDkxODIwNTEyMlowRTETMBEGA1UE
16
16
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
17
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
18
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -22,14 +22,14 @@ cert_chain:
22
22
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
23
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
24
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBBQUAA4IB
25
- AQAFoDJRokCQdxFfOrmsKX41KOFlU/zjrbDVM9hgB/Ur999M6OXGSi8FitXNtMwY
26
- FVjsiAPeU7HaWVVcZkj6IhINelTkXsxgGz/qCzjHy3iUMuZWw36cS0fiWJ5rvH+e
27
- hD7uXxJSFuyf1riDGI1aeWbQ74WMwvNstOxLUMiV5a1fzBhlxPqb537ubDjq/M/h
28
- zPUFPVYeL5KjDHLCqI2FwIk2sEMOQgjpXHzl+3NlD2LUgUhHDMevmgVua0e2GT1B
29
- xJcC6UN6NHMOVMyAXsr2HR0gRRx4ofN1LoP2KhXzSr8UMvQYlwPmE0N5GQv1b5AO
30
- VpzF30vNaJK6ZT7xlIsIlwmH
25
+ AQB+Hx8xUgrpZa4P8H8gR8zme5kISwQrG80MbpqJV6/G3/ZicRFhN5sjwu0uHGue
26
+ bd9Cymf6oIRwHVarJux2M32T6bL07Hmi07w2QaPc3MnMKB/D46SRZ2JSSGPFRBTc
27
+ SilobMRoGs/7B15uGFUEnNrCB/ltMqhwwSx1r++UQPfeySHEV9uqu03E5Vb7J37O
28
+ 2Er6PLXHRiYsIycD1LkMi6YnixdITRHmrqJYE2rsjaIfpIehiusVAPHkNf7qbpHq
29
+ qx3h45R1CAsObX0SQDIT+rRbQrtKz1GHIZTOFYvEJjUY1XmRTZupD3CJ8Q7sDqSy
30
+ NLq5jm1fq6Y9Uolu3RJbmycf
31
31
  -----END CERTIFICATE-----
32
- date: 2015-09-15 00:00:00.000000000 Z
32
+ date: 2015-11-17 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rsdl
@@ -117,7 +117,8 @@ description: |-
117
117
  email:
118
118
  - ryand-ruby@zenspider.com
119
119
  executables: []
120
- extensions: []
120
+ extensions:
121
+ - ext/sdl/extconf.rb
121
122
  extra_rdoc_files:
122
123
  - History.rdoc
123
124
  - Manifest.txt
metadata.gz.sig CHANGED
Binary file