graphics 1.0.0b6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +88 -0
- data/Manifest.txt +2 -0
- data/Rakefile +7 -8
- data/examples/boid.rb +44 -63
- data/examples/bounce.rb +4 -4
- data/examples/canvas.rb +17 -16
- data/examples/collision.rb +1 -1
- data/examples/demo.rb +1 -1
- data/examples/editor.rb +1 -1
- data/examples/fluid.rb +6 -6
- data/examples/fluid2.rb +22 -9
- data/examples/gol.rb +1 -1
- data/examples/gol2.rb +14 -22
- data/examples/math.rb +1 -1
- data/examples/pi_polygon.rb +8 -3
- data/examples/radar.rb +3 -3
- data/examples/rainbow_fluid.rb +4 -3
- data/examples/tank.rb +7 -3
- data/examples/tank2.rb +3 -3
- data/examples/targeting.rb +3 -3
- data/examples/vants.rb +13 -4
- data/examples/walker.rb +1 -1
- data/examples/walker2.rb +1 -1
- data/examples/zombies.rb +13 -7
- data/ext/sdl/extconf.rb +12 -20
- data/ext/sdl/sdl.c +619 -360
- data/ext/sdl/sge/Makefile +36 -11
- data/ext/sdl/sge/Makefile.conf +15 -9
- data/ext/sdl/sge/sge_bm_text.cpp +7 -6
- data/ext/sdl/sge/sge_collision.cpp +3 -1
- data/ext/sdl/sge/sge_config.h +0 -2
- data/ext/sdl/sge/sge_internal.h +0 -8
- data/ext/sdl/sge/sge_primitives.cpp +0 -11
- data/ext/sdl/sge/sge_primitives.h +0 -3
- data/ext/sdl/sge/sge_rotation.cpp +1 -1
- data/ext/sdl/sge/sge_shape.cpp +18 -9
- data/ext/sdl/sge/sge_surface.cpp +10 -4
- data/ext/sdl/sge/sge_textpp.cpp +17 -13
- data/graphics_setup.sh +43 -13
- data/lib/graphics.rb +1 -1
- data/lib/graphics/body.rb +8 -0
- data/lib/graphics/decorators.rb +15 -3
- data/lib/graphics/extensions.rb +1 -1
- data/lib/graphics/rainbows.rb +17 -25
- data/lib/graphics/simulation.rb +265 -106
- data/lib/graphics/v.rb +8 -1
- data/resources/sounds/attribution.txt +2 -0
- data/resources/sounds/bullet.wav +0 -0
- data/test/test_graphics.rb +232 -107
- metadata +37 -43
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d70424b07430bd3cf210e11d8bf76ec15b41231d5e1e46e8de07eaebd686e6b
|
4
|
+
data.tar.gz: 79b1367d8689c604560bdd1089f6a8ac98291bb7ee5240b3b2c10d48076e8d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8ffd685c237b1b7481f984359193c744949f6a9f30b6c57495a8fbfd5a06ef10310a607112f48ce0ad5ee83d860489cd0582c213468d67c5e7b41af85324074
|
7
|
+
data.tar.gz: 26f3cbc67a707e7ac646e1f43066806ccf8915e7313ca7d0d2bcdfd40697b4a356796bc988ca67c5100f153ac38cac7ec7b75413c605eb3f8826c27a10305d98
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,91 @@
|
|
1
|
+
=== 1.0.0 / 2018-11-13
|
2
|
+
|
3
|
+
* 4 major enhancements:
|
4
|
+
|
5
|
+
* Everything is passing around Renderer instances now.
|
6
|
+
* Moved all drawing primitives to Renderer.
|
7
|
+
* Removed rsdl dependency. Plain ruby seems to work fine now.
|
8
|
+
* Updated to work with SDL2. This will break some things, but mostly works.
|
9
|
+
|
10
|
+
* 58 minor enhancements:
|
11
|
+
|
12
|
+
* #bezier now takes an array of any number (> 4) of points.
|
13
|
+
* #blit and #put now do everything in one call. Should be more performant.
|
14
|
+
* #blit and #put now use the clear color of their class for the background.
|
15
|
+
* #clear will now warn and skip if color isn't known.
|
16
|
+
* #fps now takes an optional color
|
17
|
+
* #transform/put now explicitly rotate on their bottom-left corner. Shifting x is no longer necessary.
|
18
|
+
* AbstractRenderer#initialize clears and presents so frame 0 is correct color.
|
19
|
+
* Added DEBUG_COLOR and use it in #debug. Reversed in WhiteBackground.
|
20
|
+
* Added Graphics::Drawing#draw_on(texture).
|
21
|
+
* Added Renderer#copy_texture.
|
22
|
+
* Added Renderer#h and #w to return the output size.
|
23
|
+
* Added Renderer#new_texture
|
24
|
+
* Added Renderer#target and Renderer#target=
|
25
|
+
* Added Renderer_index to read pixels. Painfully slow in comparison.
|
26
|
+
* Added SDL::Screen::H & SDL::Screen::W and made available to your #initialize.
|
27
|
+
* Added Screen#title=.
|
28
|
+
* Added Surface#blit.
|
29
|
+
* Added Surface#clear.
|
30
|
+
* Added Surface.color_key.
|
31
|
+
* Added Window#title and Renderer#title.
|
32
|
+
* Added Window#update ? Do I need this?
|
33
|
+
* Added caching to texture in Renderer#blit. Massively speeds up boids & walker.
|
34
|
+
* Added default (empty) Body#update.
|
35
|
+
* Added unary negation to V.
|
36
|
+
* Alpha blending is massively improved. Black on white is black.
|
37
|
+
* Blit now ensures blending is on.
|
38
|
+
* Check for done before paused so `esc` can quit while paused.
|
39
|
+
* Extended Renderer#point to optionally read or write a pixel.
|
40
|
+
* Improved default window naming to add spaces to the classname.
|
41
|
+
* Moved Screen#flip to Renderer#present.
|
42
|
+
* Moved Screen#set_title to Window#set_title.
|
43
|
+
* Moving everything out of Screen class. Will remove or leave just for constants.
|
44
|
+
* Removed KeyEvent#unicode.
|
45
|
+
* Removed PixelFormat#colorkey and #alpha.
|
46
|
+
* Removed SDL::WM and set_caption. Set titles via screen.title=
|
47
|
+
* Removed Screen#update.
|
48
|
+
* Removed Simulation#alpha, now built into pixels directly.
|
49
|
+
* Removed Surface#color_key and Surface#set_color_key.
|
50
|
+
* Removed Surface#flags and Surface#set_alpha.
|
51
|
+
* Removed Surface.blit class method.
|
52
|
+
* Removed Surface.new. You only create surfaces via Font.render_text and #sprite.
|
53
|
+
* Removed bpp argument to AbstractSimulation#initialize.
|
54
|
+
* Removed/changed a lot of constants, mostly around KeyEvent handling.
|
55
|
+
* Renamed AbstractSimulation#rgb to #rgba. I think this should probably just go?
|
56
|
+
* Renamed PixelFormat.get_rgb to get_rgba.
|
57
|
+
* Renderer#fast_rect now just calls Renderer#draw_rect w/ true for filled.
|
58
|
+
* SDL2 properly supports RGBA. Switched to it entirely.
|
59
|
+
* Screen#open now stores off a renderer, window, and texture in the Surface.
|
60
|
+
* Screen.open no longer creates or stores a surface. Saves off its own PixelFormat.
|
61
|
+
* Search Ubuntu font directories in #find_font. (phiggins)
|
62
|
+
* Simulation now defaults to half-width and half-height. No more required args to super.
|
63
|
+
* Surface#save now saves off PNG.
|
64
|
+
* Switched Renderer and Window to subclass Data, not Surface.
|
65
|
+
* Switching to SDL2_gfx for primitive drawing and rotozoom.
|
66
|
+
* Transforms now default to anti-aliased rotations.
|
67
|
+
* Updated graphics_setup.sh to remove SDL1 and install SDL2 (on OSX).
|
68
|
+
* V#magnitude is now cached.
|
69
|
+
* graphics_setup.sh will install hoe if necessary.
|
70
|
+
|
71
|
+
* 15 bug fixes:
|
72
|
+
|
73
|
+
* Cleaned some off-by-one drawing bugs. I think it is more pixel perfect now?
|
74
|
+
* Cleaned up Numeric#degrees.
|
75
|
+
* Finished getting to 100% rdoc coverage.
|
76
|
+
* Fixed a memory leak in PixelFormat. Might remove it entirely.
|
77
|
+
* Fixed a memory leak in collision maps.
|
78
|
+
* Fixed an off-by-one in blitting.
|
79
|
+
* Fixed bugs in hline and vline not using correct defaults. (joshcheek)
|
80
|
+
* Fixed circle and ellipse. Filled + anti-aliased wasn't actually anti-aliased.
|
81
|
+
* Fixed examples/boid.rb to rotate bodies again.
|
82
|
+
* Fixed examples/canvas.rb to draw in black again.
|
83
|
+
* Fixed fps drawing bug in rainbow_fluid.rb
|
84
|
+
* Fixed graphics_setup.sh and Rakefile for linux.
|
85
|
+
* Functional GoL: use Set vs. Array for faster search. (sotoseattle)
|
86
|
+
* Minor fix to examples/bounce.rb for older ruby versions.
|
87
|
+
* Removed Graphics::Surface::VideoMemoryLost.
|
88
|
+
|
1
89
|
=== 1.0.0b6 / 2016-11-17
|
2
90
|
|
3
91
|
I'm still not happy with the color system. I'd love some help to make it more usable.
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require "rubygems"
|
|
4
4
|
require "hoe"
|
5
5
|
|
6
6
|
Hoe.plugin :isolate
|
7
|
-
Hoe.plugin :
|
7
|
+
Hoe.plugin :seattlerb
|
8
8
|
Hoe.plugin :rdoc
|
9
9
|
Hoe.plugin :git
|
10
10
|
Hoe.plugin :compiler
|
@@ -17,18 +17,17 @@ Hoe.spec "graphics" do
|
|
17
17
|
extension :sdl
|
18
18
|
|
19
19
|
license "MIT"
|
20
|
-
|
21
|
-
dependency "rsdl", "~> 0.1"
|
22
|
-
|
23
|
-
base = "/data/www/docs.seattlerb.org"
|
24
|
-
rdoc_locations << "docs-push.seattlerb.org:#{base}/#{remote_rdoc_dir}"
|
25
20
|
end
|
26
21
|
|
27
22
|
task :demos => :compile do
|
28
|
-
Dir["examples/*.rb"].each do |script|
|
23
|
+
Dir["examples/*.rb"].sort.each do |script|
|
29
24
|
puts script
|
30
|
-
system "
|
25
|
+
system "ruby -Ilib #{script}"
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
29
|
+
task :sanity => :compile do
|
30
|
+
sh %[ruby -Ilib -rgraphics -e 'Class.new(Graphics::Simulation) { def draw n; clear :white; text "hit escape to quit", 100, 100, :black; end; }.new(500, 250, "Working!").run']
|
31
|
+
end
|
32
|
+
|
34
33
|
# vim: syntax=ruby
|
data/examples/boid.rb
CHANGED
@@ -39,18 +39,16 @@ class Boid < Graphics::Body
|
|
39
39
|
|
40
40
|
self.velocity += v1 + v2 + v3
|
41
41
|
limit_velocity
|
42
|
-
self.position += self.velocity
|
43
42
|
|
43
|
+
move
|
44
44
|
wrap
|
45
|
-
|
46
|
-
@nearby = nil
|
47
45
|
end
|
48
46
|
|
49
47
|
def nearby
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
p = self.position
|
49
|
+
w.boids.find_all { |b|
|
50
|
+
b != self && (b.position - p).magnitude < Boid.max_distance
|
51
|
+
}
|
54
52
|
end
|
55
53
|
|
56
54
|
def limit_velocity
|
@@ -60,20 +58,11 @@ class Boid < Graphics::Body
|
|
60
58
|
end
|
61
59
|
|
62
60
|
def center_mass
|
63
|
-
|
64
|
-
nearby.each do |b|
|
65
|
-
next if self == b
|
66
|
-
|
67
|
-
pos += b.position
|
68
|
-
end
|
69
|
-
|
70
|
-
size = nearby.size - 1
|
71
|
-
|
72
|
-
return self.position if size == 0
|
61
|
+
nearby = self.nearby
|
73
62
|
|
74
|
-
|
63
|
+
return position if nearby.empty?
|
75
64
|
|
76
|
-
|
65
|
+
nearby.avg(V::ZERO, &:position)
|
77
66
|
end
|
78
67
|
|
79
68
|
##
|
@@ -180,21 +169,17 @@ class Boid < Graphics::Body
|
|
180
169
|
# enough apart for our liking.
|
181
170
|
|
182
171
|
def rule2
|
183
|
-
|
184
|
-
|
185
|
-
hits = 0
|
186
|
-
|
187
|
-
nearby.each do |b|
|
188
|
-
next if self == b
|
172
|
+
too_close = nearby.filter_map { |b|
|
189
173
|
diff = b.position - self.position
|
190
|
-
next unless diff.magnitude
|
191
|
-
|
192
|
-
|
174
|
+
next unless diff.magnitude < TOO_CLOSE
|
175
|
+
diff
|
176
|
+
}
|
177
|
+
|
178
|
+
if too_close.empty? then
|
179
|
+
V::ZERO
|
180
|
+
else
|
181
|
+
-too_close.avg(V::ZERO) / 8
|
193
182
|
end
|
194
|
-
|
195
|
-
c /= hits unless hits == 0 # average it out so they don't overdo it
|
196
|
-
|
197
|
-
c / 8
|
198
183
|
end
|
199
184
|
|
200
185
|
##
|
@@ -221,21 +206,14 @@ class Boid < Graphics::Body
|
|
221
206
|
#
|
222
207
|
# END PROCEDURE
|
223
208
|
|
224
|
-
def rule3
|
225
|
-
|
209
|
+
def rule3 # alignment
|
210
|
+
nearby = self.nearby
|
226
211
|
|
227
|
-
nearby.
|
228
|
-
next if self == b
|
229
|
-
v += b.velocity
|
230
|
-
end
|
231
|
-
|
232
|
-
size = nearby.size - 1
|
233
|
-
|
234
|
-
return self.velocity if size == 0
|
212
|
+
return velocity if nearby.empty?
|
235
213
|
|
236
|
-
v
|
214
|
+
v = nearby.avg(V::ZERO, &:velocity)
|
237
215
|
|
238
|
-
(v -
|
216
|
+
(v - velocity) / 4
|
239
217
|
end
|
240
218
|
|
241
219
|
class View
|
@@ -243,8 +221,8 @@ class Boid < Graphics::Body
|
|
243
221
|
x, y, a, m = b.x, b.y, b.a, b.m
|
244
222
|
|
245
223
|
w.circle x, y, Boid.max_distance, :gray if w.visual_debug?
|
246
|
-
w.blit w.body_img, x, y # the blit looks HORRIBLE when rotated... dunno why
|
247
224
|
w.angle x, y, a, 3 * m, :red
|
225
|
+
w.blit w.body_img, x, y, a
|
248
226
|
end
|
249
227
|
end
|
250
228
|
end
|
@@ -255,7 +233,7 @@ class Boids < Graphics::Simulation
|
|
255
233
|
alias :visual_debug? :visual_debug
|
256
234
|
|
257
235
|
def initialize
|
258
|
-
super 850, 850
|
236
|
+
super 850, 850
|
259
237
|
|
260
238
|
self.visual_debug = false
|
261
239
|
|
@@ -263,7 +241,7 @@ class Boids < Graphics::Simulation
|
|
263
241
|
register_bodies boids
|
264
242
|
|
265
243
|
self.body_img = sprite 20, 20 do
|
266
|
-
circle 10, 10, 5, :white, :filled
|
244
|
+
circle 10, 10, 5, :white, :filled, :aa
|
267
245
|
end
|
268
246
|
end
|
269
247
|
|
@@ -283,14 +261,18 @@ class Boids < Graphics::Simulation
|
|
283
261
|
end
|
284
262
|
end
|
285
263
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
264
|
+
module Enumerable
|
265
|
+
def filter_map &block
|
266
|
+
map(&block).select(&:itself)
|
267
|
+
end
|
268
|
+
|
269
|
+
def avg init=0, &block
|
270
|
+
sum(init, &block) / length
|
291
271
|
end
|
292
272
|
end
|
293
273
|
|
274
|
+
Boids.new.run
|
275
|
+
|
294
276
|
# Further tweaks
|
295
277
|
#
|
296
278
|
# The three boids rules sufficiently demonstrate a complex emergent
|
@@ -310,8 +292,8 @@ end
|
|
310
292
|
# v1 = rule1(b)
|
311
293
|
# v2 = rule2(b)
|
312
294
|
# v3 = rule3(b)
|
313
|
-
#
|
314
|
-
#
|
295
|
+
# v4 = rule4(b)
|
296
|
+
# .
|
315
297
|
# .
|
316
298
|
# .
|
317
299
|
#
|
@@ -473,19 +455,18 @@ end
|
|
473
455
|
# PROCEDURE move_all_boids_to_new_positions()
|
474
456
|
#
|
475
457
|
# Vector v1, v2, v3, ...
|
476
|
-
#
|
458
|
+
# Boid b
|
477
459
|
#
|
478
460
|
# FOR EACH BOID b
|
479
461
|
#
|
480
462
|
# IF b.perching THEN
|
481
|
-
#
|
482
|
-
#
|
483
|
-
#
|
484
|
-
#
|
485
|
-
#
|
486
|
-
#
|
487
|
-
#
|
488
|
-
#
|
463
|
+
# IF b.perch_timer > 0 THEN
|
464
|
+
# b.perch_timer = b.perch_timer - 1
|
465
|
+
# NEXT
|
466
|
+
# ELSE
|
467
|
+
# b.perching = FALSE
|
468
|
+
# END IF
|
469
|
+
# END IF
|
489
470
|
#
|
490
471
|
# v1 = rule1(b)
|
491
472
|
# v2 = rule2(b)
|
data/examples/bounce.rb
CHANGED
@@ -29,8 +29,8 @@ class Ball < Graphics::Body
|
|
29
29
|
|
30
30
|
class View
|
31
31
|
def self.draw w, b
|
32
|
-
w.angle
|
33
|
-
w.circle b.x, b.y, 5,
|
32
|
+
w.angle b.x, b.y, b.a, 10+3*b.m, :red
|
33
|
+
w.circle b.x, b.y, 5, :white, :filled
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -39,7 +39,7 @@ class BounceSimulation < Graphics::Simulation
|
|
39
39
|
attr_accessor :bs
|
40
40
|
|
41
41
|
def initialize
|
42
|
-
super
|
42
|
+
super
|
43
43
|
|
44
44
|
self.bs = populate Ball
|
45
45
|
register_bodies bs
|
@@ -72,7 +72,7 @@ class BounceSimulation < Graphics::Simulation
|
|
72
72
|
LOG_INTERVAL = 120
|
73
73
|
|
74
74
|
def log
|
75
|
-
puts bs.
|
75
|
+
puts "%.1f" % bs.inject(0) { |ms, o| ms + o.m }
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/examples/canvas.rb
CHANGED
@@ -6,19 +6,19 @@ require "graphics"
|
|
6
6
|
class Demo < Graphics::Simulation
|
7
7
|
CLEAR_COLOR = :white
|
8
8
|
|
9
|
-
attr_accessor :woot, :
|
9
|
+
attr_accessor :woot, :big_font
|
10
10
|
attr_accessor :rct
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
super 801, 801
|
14
14
|
|
15
|
-
self.font = find_font(
|
16
|
-
self.
|
15
|
+
self.font = find_font(DEFAULT_FONT, 16)
|
16
|
+
self.big_font = find_font(DEFAULT_FONT, 32)
|
17
17
|
|
18
|
-
self.woot = render_text "woot", :black,
|
18
|
+
self.woot = render_text "woot", :black, big_font
|
19
19
|
|
20
20
|
self.rct = sprite 50, 25 do
|
21
|
-
rect 0, 0, 49, 24, :
|
21
|
+
rect 0, 0, 49, 24, :black
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -32,18 +32,17 @@ class Demo < Graphics::Simulation
|
|
32
32
|
clear
|
33
33
|
|
34
34
|
(0..90).step(30) do |deg|
|
35
|
-
|
36
|
-
put woot, 400-shift, 300, deg
|
35
|
+
put woot, 400, 300, deg
|
37
36
|
end
|
38
|
-
text "woot", 400, 300, :red,
|
37
|
+
text "woot", 400, 300, :red, big_font
|
39
38
|
|
40
|
-
rect 550, 100, 50, 50, :
|
41
|
-
rect 575, 125, 50, 50, :
|
39
|
+
rect 550, 100, 50, 50, :black, :filled
|
40
|
+
rect 575, 125, 50, 50, :black
|
42
41
|
|
43
42
|
ellipse 550, 200, 50, 25, :red
|
44
43
|
ellipse 550, 250, 50, 25, :red, :filled
|
45
44
|
|
46
|
-
angle 50, 50, 90, 25, :
|
45
|
+
angle 50, 50, 90, 25, :black
|
47
46
|
|
48
47
|
(0..w).step(100) do |x|
|
49
48
|
vline x, :red
|
@@ -55,22 +54,24 @@ class Demo < Graphics::Simulation
|
|
55
54
|
text y.to_s, 5, y+5, :black
|
56
55
|
end
|
57
56
|
|
58
|
-
circle 200, 200, 100, :
|
59
|
-
text "circle 200, 200, 100, :
|
57
|
+
circle 200, 200, 100, :black
|
58
|
+
text "circle 200, 200, 100, :black", 100, 200, :black
|
60
59
|
|
61
|
-
bezier 400, 400, 450, 700, 550, 300, 600, 600, :
|
62
|
-
text "bezier 400, 400, 450, 700, 550, 300, 600, 600, :
|
60
|
+
bezier 400, 400, 450, 700, 550, 300, 600, 600, :black
|
61
|
+
text "bezier 400, 400, 450, 700, 550, 300, 600, 600, :black", 200, 400, :black
|
63
62
|
|
64
63
|
angle 200, 500, A, L, :black
|
65
64
|
text "angle 200, 500, %.2f, %.2f, :black" % [A, L], 100, 500, :black
|
66
65
|
|
67
66
|
(0..90).step(30).each do |deg|
|
68
|
-
put rct, 500
|
67
|
+
put rct, 500, 600, deg
|
69
68
|
angle 500, 600, deg, 50, :red
|
70
69
|
|
71
70
|
blit rct, 600, 600, deg
|
72
71
|
angle 600, 600, deg, 50, :red
|
73
72
|
end
|
73
|
+
text "put rct, 500, 600, deg", 500, 600-30, :black
|
74
|
+
text "blit rct, 600, 600, deg", 600, 600-60, :black
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|