graphics 1.0.0b6 → 1.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 +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
data/lib/graphics/v.rb
CHANGED
@@ -39,6 +39,13 @@ class V
|
|
39
39
|
V[x-v.x, y-v.y]
|
40
40
|
end
|
41
41
|
|
42
|
+
##
|
43
|
+
# Unary negation.
|
44
|
+
|
45
|
+
def -@
|
46
|
+
V[-x, -y]
|
47
|
+
end
|
48
|
+
|
42
49
|
##
|
43
50
|
# Multiply a vector by a scalar, returning a new vector.
|
44
51
|
|
@@ -61,7 +68,7 @@ class V
|
|
61
68
|
# Return the length of the vector from the origin.
|
62
69
|
|
63
70
|
def magnitude
|
64
|
-
Math.sqrt(x*x + y*y)
|
71
|
+
@magnitude ||= Math.sqrt(x*x + y*y)
|
65
72
|
end
|
66
73
|
|
67
74
|
def inspect # :nodoc:
|
Binary file
|
data/test/test_graphics.rb
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
require "minitest/autorun"
|
4
4
|
require "graphics"
|
5
5
|
|
6
|
+
class FakeSimulation < Graphics::Simulation
|
7
|
+
def initialize
|
8
|
+
SDL.init SDL::INIT_VIDEO # HACK? Used to be in Simulation#initialize
|
9
|
+
super 300, 200
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
class TestBody < Minitest::Test
|
7
14
|
attr_accessor :w, :b
|
8
15
|
|
@@ -298,116 +305,167 @@ class TestNumeric < Minitest::Test
|
|
298
305
|
end
|
299
306
|
|
300
307
|
class TestSimulation < Minitest::Test
|
301
|
-
|
308
|
+
class FakePixelFormat < SDL::PixelFormat
|
309
|
+
def initialize
|
310
|
+
|
311
|
+
end
|
312
|
+
end
|
302
313
|
|
303
|
-
class FakeSimulation <
|
314
|
+
class FakeSimulation < ::FakeSimulation
|
304
315
|
def initialize
|
305
|
-
super
|
316
|
+
super
|
306
317
|
|
307
318
|
s = []
|
308
319
|
|
320
|
+
sc = s.singleton_class
|
321
|
+
|
322
|
+
sc.send :undef_method, :clear
|
323
|
+
sc.send :undef_method, :[]=
|
324
|
+
|
309
325
|
def s.method_missing *a
|
310
326
|
@data ||= []
|
311
327
|
@data << a
|
328
|
+
self
|
312
329
|
end
|
313
330
|
|
314
331
|
def s.data
|
315
332
|
@data
|
316
333
|
end
|
317
334
|
|
318
|
-
|
335
|
+
pf = self.renderer.format
|
336
|
+
|
337
|
+
s.instance_variable_set :@format, pf
|
338
|
+
|
339
|
+
self.renderer = s
|
319
340
|
end
|
320
341
|
end
|
321
342
|
|
322
|
-
attr_accessor :t, :white, :exp
|
343
|
+
attr_accessor :t, :white, :black, :exp, :h
|
323
344
|
|
324
345
|
def setup
|
325
346
|
self.t = FakeSimulation.new
|
326
347
|
self.white = t.color[:white]
|
348
|
+
self.black = t.color[:black]
|
327
349
|
self.exp = []
|
350
|
+
self.h = t.h-1
|
328
351
|
end
|
329
352
|
|
330
|
-
def
|
331
|
-
|
353
|
+
def assert_drawing *calls
|
354
|
+
exp.concat calls
|
332
355
|
|
333
|
-
|
334
|
-
|
356
|
+
assert_equal exp, t.renderer.data
|
357
|
+
end
|
335
358
|
|
336
|
-
|
337
|
-
|
359
|
+
def test_angle
|
360
|
+
d45 = 10 * Math.sqrt(2) / 2
|
338
361
|
|
362
|
+
t.angle 50, 50, 0, 10, :white
|
363
|
+
t.angle 50, 50, 90, 10, :white
|
339
364
|
t.angle 50, 50, 180, 10, :white
|
340
|
-
exp << [:draw_line, 50, h-50, 40.0, h-50.0, white]
|
341
|
-
|
342
365
|
t.angle 50, 50, 270, 10, :white
|
343
|
-
|
366
|
+
t.angle 50, 50, 45, 10, :white
|
344
367
|
|
345
|
-
|
346
|
-
|
347
|
-
|
368
|
+
assert_drawing([:draw_line, 50, h-50, 60.0, h-50, white, true],
|
369
|
+
[:draw_line, 50, h-50, 50.0, h-60, white, true],
|
370
|
+
[:draw_line, 50, h-50, 40.0, h-50, white, true],
|
371
|
+
[:draw_line, 50, h-50, 50.0, h-40, white, true],
|
372
|
+
[:draw_line, 50, h-50, 50+d45, h-50-d45, white, true])
|
373
|
+
end
|
348
374
|
|
349
|
-
|
375
|
+
def test_bezier
|
376
|
+
t.bezier 50, 50, 25, 25, 100, 25, :white
|
377
|
+
|
378
|
+
assert_drawing [:draw_bezier, [50, 25, 100], [h-50, h-25, h-25], 5, white]
|
350
379
|
end
|
351
380
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
381
|
+
def test_blit
|
382
|
+
s = t.render_text "blah", :white
|
383
|
+
|
384
|
+
assert_instance_of SDL::Surface, s
|
385
|
+
assert_equal [76, 38], [s.w, s.h]
|
386
|
+
|
387
|
+
t.blit s, 100, 10
|
388
|
+
|
389
|
+
assert_drawing [:blit, s, 100-(76/2), h-(38/2)-10+1, nil, nil, nil, :center]
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_put
|
393
|
+
s = t.render_text "blah", :white
|
394
|
+
|
395
|
+
assert_instance_of SDL::Surface, s
|
396
|
+
assert_equal [76, 38], [s.w, s.h]
|
397
|
+
|
398
|
+
t.put s, 10, 10
|
399
|
+
|
400
|
+
# TODO: extra -1 / +1 doesn't make sense
|
401
|
+
assert_drawing [:blit, s, 10, h-38-10+1, nil, nil, nil, false]
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_circle
|
405
|
+
t.circle 50, 50, 25, :white
|
406
|
+
t.circle 50, 50, 25, :white, :filled
|
407
|
+
|
408
|
+
t.circle 50, 50, 25, :white, false, false
|
409
|
+
t.circle 50, 50, 25, :white, :filled, false
|
410
|
+
|
411
|
+
assert_drawing([:draw_circle, 50, 149, 25, white, true, false],
|
412
|
+
[:draw_circle, 50, 149, 25, white, true, :filled],
|
413
|
+
[:draw_circle, 50, 149, 25, white, false, false],
|
414
|
+
[:draw_circle, 50, 149, 25, white, false, :filled])
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_clear
|
418
|
+
t.clear
|
419
|
+
t.clear :white
|
420
|
+
|
421
|
+
assert_drawing([:clear, black],
|
422
|
+
[:clear, white])
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_debug
|
426
|
+
skip "not yet, figure out test_text first"
|
427
|
+
|
428
|
+
raise NotImplementedError, 'Need to write test_debug'
|
429
|
+
end
|
379
430
|
|
380
431
|
def test_ellipse
|
381
432
|
t.ellipse 0, 0, 25, 25, :white
|
382
433
|
|
383
|
-
h
|
384
|
-
|
434
|
+
assert_drawing [:draw_ellipse, 0, h, 25, 25, t.color[:white], true, false]
|
435
|
+
end
|
436
|
+
|
437
|
+
def test_fast_rect
|
438
|
+
t.fast_rect 25, 25, 10, 20, :white
|
439
|
+
t.fast_rect 0, 0, 100, 100, :white
|
385
440
|
|
386
|
-
|
441
|
+
assert_drawing([:fast_rect, 25, h+1-25-20, 10, 20, white],
|
442
|
+
[:fast_rect, 0, h+1-0-100, 100, 100, white])
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_fps
|
446
|
+
skip "not yet, figure out test_text first"
|
447
|
+
|
448
|
+
t.start_time = Time.now - 1
|
449
|
+
|
450
|
+
t.fps 42
|
451
|
+
|
452
|
+
assert_drawing
|
387
453
|
end
|
388
454
|
|
389
|
-
# def test_fast_rect
|
390
|
-
# raise NotImplementedError, 'Need to write test_fast_rect'
|
391
|
-
# end
|
392
|
-
#
|
393
|
-
# def test_fps
|
394
|
-
# raise NotImplementedError, 'Need to write test_fps'
|
395
|
-
# end
|
396
|
-
#
|
397
455
|
# def test_handle_event
|
398
456
|
# raise NotImplementedError, 'Need to write test_handle_event'
|
399
457
|
# end
|
400
|
-
|
458
|
+
|
401
459
|
# def test_handle_keys
|
402
460
|
# raise NotImplementedError, 'Need to write test_handle_keys'
|
403
461
|
# end
|
404
462
|
|
405
463
|
def test_hline
|
406
464
|
t.hline 42, :white
|
407
|
-
|
408
|
-
exp << [:draw_line, 0, h-42, 100, h-42, t.color[:white]]
|
465
|
+
t.hline 0, :white
|
409
466
|
|
410
|
-
|
467
|
+
assert_drawing([:draw_line, 0, h-42, 300, h-42, t.color[:white], true],
|
468
|
+
[:draw_line, 0, h- 0, 300, h- 0, t.color[:white], true])
|
411
469
|
end
|
412
470
|
|
413
471
|
# def test_image
|
@@ -415,68 +473,135 @@ class TestSimulation < Minitest::Test
|
|
415
473
|
# end
|
416
474
|
|
417
475
|
def test_line
|
476
|
+
t.line 0, 0, 25, 0, :white
|
477
|
+
t.line 0, 0, 0, 25, :white
|
418
478
|
t.line 0, 0, 25, 25, :white
|
419
|
-
|
420
|
-
|
479
|
+
t.line 0, 0, 25, 25, :white, false
|
480
|
+
|
481
|
+
t.line 0, 200-1, 25, 200-1, :white
|
482
|
+
t.line 0, 200-1, 0, 200-1-25, :white
|
483
|
+
t.line 0, 200-1, 25, 200-1-25, :white
|
421
484
|
|
422
|
-
|
485
|
+
assert_drawing([:draw_line, 0, h, 25, h- 0, t.color[:white], true],
|
486
|
+
[:draw_line, 0, h, 0, h-25, t.color[:white], true],
|
487
|
+
[:draw_line, 0, h, 25, h-25, t.color[:white], true],
|
488
|
+
[:draw_line, 0, h, 25, h-25, t.color[:white], false],
|
489
|
+
[:draw_line, 0, 0, 25, 0, t.color[:white], true],
|
490
|
+
[:draw_line, 0, 0, 0, 25, t.color[:white], true],
|
491
|
+
[:draw_line, 0, 0, 25, 25, t.color[:white], true])
|
423
492
|
end
|
424
493
|
|
425
494
|
def test_point
|
426
|
-
skip "not yet"
|
427
495
|
t.point 2, 10, :white
|
428
496
|
|
429
|
-
|
430
|
-
|
497
|
+
assert_drawing [:[]=, 2, h-10, white]
|
498
|
+
end
|
431
499
|
|
432
|
-
|
500
|
+
def test_populate
|
501
|
+
skip "not done yet"
|
433
502
|
end
|
434
503
|
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
504
|
+
make_my_diffs_pretty!
|
505
|
+
|
506
|
+
|
507
|
+
def test_rect
|
508
|
+
t.rect 25, 25, 10, 20, :white
|
509
|
+
t.rect 0, 0, 100, 100, :white
|
510
|
+
t.rect 25, 25, 10, 20, :white, :filled
|
511
|
+
|
512
|
+
assert_drawing([:draw_rect, 25, h+1-25-20, 10, 20, white, false],
|
513
|
+
[:draw_rect, 0, h+1-0-100, 100, 100, white, false],
|
514
|
+
[:draw_rect, 25, h+1-25-20, 10, 20, white, :filled])
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_register_color
|
518
|
+
skip "not done yet"
|
519
|
+
end
|
520
|
+
|
521
|
+
def test_render_text
|
522
|
+
s = t.render_text("blah", :black)
|
523
|
+
|
524
|
+
assert_instance_of SDL::Surface, s
|
525
|
+
assert_equal [76, 38], [s.w, s.h]
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_run
|
529
|
+
skip "not done yet"
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_sprite
|
533
|
+
skip "not done yet"
|
534
|
+
end
|
535
|
+
|
536
|
+
def test_text
|
537
|
+
skip "um... not sure how to test this yet"
|
538
|
+
|
539
|
+
t.text "woot", 25, 25, :white
|
540
|
+
|
541
|
+
assert_drawing
|
542
|
+
end
|
543
|
+
|
544
|
+
def test_text_size
|
545
|
+
assert_equal [76, 38], t.text_size("blah")
|
546
|
+
assert_equal [ 0, 38], t.text_size("")
|
547
|
+
assert_equal [76, 38], t.text_size(:blah)
|
548
|
+
end
|
549
|
+
|
550
|
+
def test_update
|
551
|
+
skip "not done yet"
|
552
|
+
end
|
553
|
+
|
554
|
+
def test_vline
|
555
|
+
t.vline 0, :white
|
556
|
+
t.vline 42, :white
|
557
|
+
|
558
|
+
assert_drawing([:draw_line, 0, 0, 0, h, t.color[:white], true],
|
559
|
+
[:draw_line, 42, 0, 42, h, t.color[:white], true])
|
560
|
+
end
|
561
|
+
|
562
|
+
def test_from_hsl
|
563
|
+
assert_equal [ 0, 0, 0], t.from_hsl( 0, 0, 0) # Black
|
564
|
+
assert_equal [255, 255, 255], t.from_hsl( 0, 0, 1) # White
|
565
|
+
assert_equal [255, 0, 0], t.from_hsl( 0, 1, 0.50) # Red
|
566
|
+
assert_equal [ 0, 255, 0], t.from_hsl(120, 1, 0.50) # Lime
|
567
|
+
assert_equal [ 0, 0, 255], t.from_hsl(240, 1, 0.50) # Blue
|
568
|
+
assert_equal [255, 255, 0], t.from_hsl( 60, 1, 0.50) # Yellow
|
569
|
+
assert_equal [ 0, 255, 255], t.from_hsl(180, 1, 0.50) # Cyan
|
570
|
+
assert_equal [255, 0, 255], t.from_hsl(300, 1, 0.50) # Magenta
|
571
|
+
assert_equal [191, 191, 191], t.from_hsl( 0, 0, 0.75) # Silver
|
572
|
+
assert_equal [128, 128, 128], t.from_hsl( 0, 0, 0.50) # Gray
|
573
|
+
assert_equal [128, 0, 0], t.from_hsl( 0, 1, 0.25) # Maroon
|
574
|
+
assert_equal [128, 128, 0], t.from_hsl( 60, 1, 0.25) # Olive
|
575
|
+
assert_equal [ 0, 128, 0], t.from_hsl(120, 1, 0.25) # Green
|
576
|
+
assert_equal [128, 0, 128], t.from_hsl(300, 1, 0.25) # Purple
|
577
|
+
assert_equal [ 0, 128, 128], t.from_hsl(180, 1, 0.25) # Teal
|
578
|
+
assert_equal [ 0, 0, 128], t.from_hsl(240, 1, 0.25) # Navy
|
579
|
+
end
|
580
|
+
|
581
|
+
def test_from_hsv
|
582
|
+
assert_equal [ 0, 0, 0], t.from_hsv( 0, 0, 0) # Black
|
583
|
+
assert_equal [255, 255, 255], t.from_hsv( 0, 0, 1) # White
|
584
|
+
assert_equal [255, 0, 0], t.from_hsv( 0, 1, 1) # Red
|
585
|
+
assert_equal [ 0, 255, 0], t.from_hsv(120, 1, 1) # Lime
|
586
|
+
assert_equal [ 0, 0, 255], t.from_hsv(240, 1, 1) # Blue
|
587
|
+
assert_equal [255, 255, 0], t.from_hsv( 60, 1, 1) # Yellow
|
588
|
+
assert_equal [ 0, 255, 255], t.from_hsv(180, 1, 1) # Cyan
|
589
|
+
assert_equal [255, 0, 255], t.from_hsv(300, 1, 1) # Magenta
|
590
|
+
assert_equal [191, 191, 191], t.from_hsv( 0, 0, 0.75) # Silver
|
591
|
+
assert_equal [128, 128, 128], t.from_hsv( 0, 0, 0.50) # Gray
|
592
|
+
assert_equal [128, 0, 0], t.from_hsv( 0, 1, 0.50) # Maroon
|
593
|
+
assert_equal [128, 128, 0], t.from_hsv( 60, 1, 0.50) # Olive
|
594
|
+
assert_equal [ 0, 128, 0], t.from_hsv(120, 1, 0.50) # Green
|
595
|
+
assert_equal [128, 0, 128], t.from_hsv(300, 1, 0.50) # Purple
|
596
|
+
assert_equal [ 0, 128, 128], t.from_hsv(180, 1, 0.50) # Teal
|
597
|
+
assert_equal [ 0, 0, 128], t.from_hsv(240, 1, 0.50) # Navy
|
598
|
+
end
|
474
599
|
end
|
475
600
|
|
476
601
|
require 'graphics/rainbows'
|
477
602
|
class TestGraphics < Minitest::Test
|
478
603
|
def setup
|
479
|
-
@t =
|
604
|
+
@t = FakeSimulation.new
|
480
605
|
end
|
481
606
|
|
482
607
|
def test_registering_rainbows
|