graphics 1.0.0b1 → 1.0.0b4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/History.rdoc +30 -0
  5. data/Manifest.txt +39 -7
  6. data/README.rdoc +48 -4
  7. data/Rakefile +8 -2
  8. data/examples/boid.rb +9 -18
  9. data/examples/bounce.rb +15 -23
  10. data/examples/canvas.rb +75 -0
  11. data/examples/collision.rb +6 -6
  12. data/examples/demo.rb +5 -7
  13. data/examples/editor.rb +12 -9
  14. data/examples/fluid.rb +2 -3
  15. data/examples/fluid2.rb +1 -1
  16. data/examples/{lito2.rb → gol.rb} +0 -0
  17. data/examples/{zenspider4.rb → gol2.rb} +0 -0
  18. data/examples/logo.rb +4 -7
  19. data/examples/maze.rb +136 -0
  20. data/examples/tank.rb +10 -11
  21. data/examples/tank2.rb +12 -17
  22. data/examples/targeting.rb +1 -1
  23. data/examples/vants.rb +1 -1
  24. data/examples/walker.rb +3 -12
  25. data/examples/walker2.rb +197 -0
  26. data/examples/zombies.rb +31 -35
  27. data/ext/sdl/extconf.rb +31 -0
  28. data/ext/sdl/sdl.c +1067 -0
  29. data/ext/sdl/sge/INSTALL +72 -0
  30. data/ext/sdl/sge/LICENSE +504 -0
  31. data/ext/sdl/sge/Makefile +83 -0
  32. data/ext/sdl/sge/Makefile.conf +63 -0
  33. data/ext/sdl/sge/README +219 -0
  34. data/ext/sdl/sge/Todo +7 -0
  35. data/ext/sdl/sge/WhatsNew +224 -0
  36. data/ext/sdl/sge/sge.h +31 -0
  37. data/ext/sdl/sge/sge_blib.cpp +1939 -0
  38. data/ext/sdl/sge/sge_blib.h +68 -0
  39. data/ext/sdl/sge/sge_bm_text.cpp +451 -0
  40. data/ext/sdl/sge/sge_bm_text.h +71 -0
  41. data/ext/sdl/sge/sge_collision.cpp +388 -0
  42. data/ext/sdl/sge/sge_collision.h +54 -0
  43. data/ext/sdl/sge/sge_config.h +6 -0
  44. data/ext/sdl/sge/sge_internal.h +152 -0
  45. data/ext/sdl/sge/sge_misc.cpp +92 -0
  46. data/ext/sdl/sge/sge_misc.h +37 -0
  47. data/ext/sdl/sge/sge_primitives.cpp +2516 -0
  48. data/ext/sdl/sge/sge_primitives.h +111 -0
  49. data/ext/sdl/sge/sge_rotation.cpp +683 -0
  50. data/ext/sdl/sge/sge_rotation.h +46 -0
  51. data/ext/sdl/sge/sge_shape.cpp +762 -0
  52. data/ext/sdl/sge/sge_shape.h +365 -0
  53. data/ext/sdl/sge/sge_surface.cpp +1090 -0
  54. data/ext/sdl/sge/sge_surface.h +100 -0
  55. data/ext/sdl/sge/sge_textpp.cpp +785 -0
  56. data/ext/sdl/sge/sge_textpp.h +270 -0
  57. data/ext/sdl/sge/sge_tt_text.cpp +1456 -0
  58. data/ext/sdl/sge/sge_tt_text.h +114 -0
  59. data/graphics_setup.sh +26 -0
  60. data/lib/graphics.rb +1 -1
  61. data/lib/graphics/body.rb +50 -3
  62. data/lib/graphics/extensions.rb +13 -7
  63. data/lib/graphics/simulation.rb +126 -46
  64. data/test/test_graphics.rb +52 -12
  65. data/test/test_sdl.rb +1 -0
  66. metadata +54 -23
  67. metadata.gz.sig +0 -0
  68. data/.gemtest +0 -0
  69. data/examples/lito.rb +0 -108
  70. data/examples/zenspider1.rb +0 -93
  71. data/examples/zenspider2.rb +0 -123
  72. data/examples/zenspider3.rb +0 -104
  73. data/rubysdl_setup.sh +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db37414cb4bf4a73f707c922329202ada329be1
4
- data.tar.gz: 57d39f17362848aa3c4e896ca5eee74f10bdac56
3
+ metadata.gz: 0dc93f577bc8db9cd0a1943285badd63a7a8b993
4
+ data.tar.gz: c83fbd5e05b5a3e9294e5271f18e17310d7c122e
5
5
  SHA512:
6
- metadata.gz: 907e6750f1311907d6083bbb09e87b51ad32c401b8990aa47ccb5645bc98c362ab2d9d4d41057b8dfab858a0370b402da7a53ce001647c8ce202f7a9125e1565
7
- data.tar.gz: 6f4edf4b031ca928dda681d270c885870ed3be0a536028290c7a0d629edec1d28092a6e2a8db6aa177865632d8bfe2601d51caa370dead3a40887c01ad3a253a
6
+ metadata.gz: a1a192627f226b8215af1e5b39bead9e16cf06c41937053e5cd2e627f6f35dff581b1d575356dea21f105f1aa46c3d49c26c3e42c9cd8906ea0eaaad50c13e58
7
+ data.tar.gz: a22e5142715d85c7f1bd254b7ea478ad1ea185c110d7f93a0cfcc3537d8a6586210987ee7ecde9a842c40b66b64e70e75412aa30040e96b0064087de47088acb
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,33 @@
1
+ === 1.0.0b4 / 2015-09-14
2
+
3
+ * 1 major enhancement:
4
+
5
+ * MAJOR rewrite. Replaced rubysdl with my own C extension.
6
+ * This unencumbers me from rubysdl, which was incomplete, LGPL, and hasn't had a commit in over a year.
7
+
8
+ * 11 minor enhancements:
9
+
10
+ * Added Body#angle_to
11
+ * Added Body#distance_to_squared
12
+ * Added Simulation#iter_per_tick and changed update to run that number of
13
+ * Added examples/canvas.rb to show drawing coordinate system.
14
+ * Added maze example from Jamis Buck's Mazes for Programmers.
15
+ * All blits are antialiased and default to 0deg rotation.
16
+ * Removed TTF.init
17
+ * Shift drawing of nearly all things by 1px in y. Makes drawing hline at 0 visible.
18
+ * Text now uses draw_blended_utf8 for smoother text rendering
19
+ * Updated rubysdl_setup.sh to be more correct. Not quite complete yet.
20
+ * Better math. powered by scotch™
21
+
22
+ * 6 bug fixes:
23
+
24
+ * Documented basic attribs of Body.
25
+ * Fixed drawing at y=0. Off by one, yo.
26
+ * Fixed fill_rect for y=0
27
+ * Fixed north/south reporting in clip now that we're in proper q1
28
+ * Fixed polygon refactor
29
+ * Fixed project url and got rdoc upload url set up correctly.
30
+
1
31
  === 1.0.0b1 / 2015-08-04
2
32
 
3
33
  * 1 major enhancement
@@ -5,26 +5,58 @@ README.rdoc
5
5
  Rakefile
6
6
  examples/boid.rb
7
7
  examples/bounce.rb
8
+ examples/canvas.rb
8
9
  examples/collision.rb
9
10
  examples/demo.rb
10
11
  examples/editor.rb
11
12
  examples/fluid.rb
12
13
  examples/fluid2.rb
13
- examples/lito.rb
14
- examples/lito2.rb
14
+ examples/gol.rb
15
+ examples/gol2.rb
15
16
  examples/logo.rb
16
17
  examples/math.rb
18
+ examples/maze.rb
17
19
  examples/radar.rb
18
20
  examples/tank.rb
19
21
  examples/tank2.rb
20
22
  examples/targeting.rb
21
23
  examples/vants.rb
22
24
  examples/walker.rb
23
- examples/zenspider1.rb
24
- examples/zenspider2.rb
25
- examples/zenspider3.rb
26
- examples/zenspider4.rb
25
+ examples/walker2.rb
27
26
  examples/zombies.rb
27
+ ext/sdl/extconf.rb
28
+ ext/sdl/sdl.c
29
+ ext/sdl/sge/INSTALL
30
+ ext/sdl/sge/LICENSE
31
+ ext/sdl/sge/Makefile
32
+ ext/sdl/sge/Makefile.conf
33
+ ext/sdl/sge/README
34
+ ext/sdl/sge/Todo
35
+ ext/sdl/sge/WhatsNew
36
+ ext/sdl/sge/sge.h
37
+ ext/sdl/sge/sge_blib.cpp
38
+ ext/sdl/sge/sge_blib.h
39
+ ext/sdl/sge/sge_bm_text.cpp
40
+ ext/sdl/sge/sge_bm_text.h
41
+ ext/sdl/sge/sge_collision.cpp
42
+ ext/sdl/sge/sge_collision.h
43
+ ext/sdl/sge/sge_config.h
44
+ ext/sdl/sge/sge_internal.h
45
+ ext/sdl/sge/sge_misc.cpp
46
+ ext/sdl/sge/sge_misc.h
47
+ ext/sdl/sge/sge_primitives.cpp
48
+ ext/sdl/sge/sge_primitives.h
49
+ ext/sdl/sge/sge_rotation.cpp
50
+ ext/sdl/sge/sge_rotation.h
51
+ ext/sdl/sge/sge_shape.cpp
52
+ ext/sdl/sge/sge_shape.h
53
+ ext/sdl/sge/sge_surface.cpp
54
+ ext/sdl/sge/sge_surface.h
55
+ ext/sdl/sge/sge_textpp.cpp
56
+ ext/sdl/sge/sge_textpp.h
57
+ ext/sdl/sge/sge_tt_text.cpp
58
+ ext/sdl/sge/sge_tt_text.h
59
+ graphics_setup.sh
28
60
  lib/graphics.rb
29
61
  lib/graphics/body.rb
30
62
  lib/graphics/extensions.rb
@@ -33,5 +65,5 @@ lib/graphics/trail.rb
33
65
  lib/graphics/v.rb
34
66
  resources/images/body.png
35
67
  resources/images/turret.png
36
- rubysdl_setup.sh
37
68
  test/test_graphics.rb
69
+ test/test_sdl.rb
@@ -1,6 +1,6 @@
1
1
  = graphics
2
2
 
3
- home :: https://github.com/seattlerb/graphics
3
+ home :: https://github.com/zenspider/graphics
4
4
  rdoc :: http://docs.seattlerb.org/graphics
5
5
 
6
6
  == DESCRIPTION:
@@ -27,15 +27,59 @@ when implementing your simulation.
27
27
 
28
28
  == SYNOPSIS:
29
29
 
30
- See examples/*.rb
30
+ class Ball < Graphics::Body
31
+ def initialize w
32
+ super
33
+
34
+ # ...
35
+ end
36
+
37
+ def draw
38
+ w.angle x, y, a, 10+3*m, :red
39
+ w.circle x, y, 5, :white, :filled
40
+ end
41
+
42
+ def update
43
+ fall
44
+ move
45
+ bounce
46
+ end
47
+
48
+ # ...
49
+ end
50
+
51
+ class BounceSimulation < Graphics::Simulation
52
+ attr_accessor :bs
53
+
54
+ def initialize
55
+ super 640, 640, 16, "Bounce"
56
+
57
+ self.bs = populate Ball
58
+ end
59
+
60
+ def update n
61
+ bs.each(&:update)
62
+ end
63
+
64
+ def draw n
65
+ clear
66
+ bs.each(&:draw)
67
+ fps n
68
+ end
69
+
70
+ # ...
71
+ end
72
+
73
+ BounceSimulation.new.run
74
+
75
+ See examples/*.rb for more
31
76
 
32
77
  == REQUIREMENTS:
33
78
 
34
79
  * rsdl
35
- * ruby-sdl
36
80
  * libsdl & friends
37
81
 
38
- See and/or run rubysdl_setup.sh. If you're on OSX and have homebrew
82
+ See and/or run graphics_setup.sh. If you're on OSX and have homebrew
39
83
  installed, running this will ensure you have a working setup.
40
84
 
41
85
  You may want to run `brew update` beforehand to ensure you get
data/Rakefile CHANGED
@@ -7,16 +7,22 @@ Hoe.plugin :isolate
7
7
  Hoe.plugin :minitest, :history, :email # Hoe.plugin :seattlerb - :perforce
8
8
  Hoe.plugin :rdoc
9
9
  Hoe.plugin :git
10
+ Hoe.plugin :compiler
10
11
 
11
12
  Hoe.spec "graphics" do
12
13
  developer "Ryan Davis", "ryand-ruby@zenspider.com"
14
+
15
+ extension :sdl
16
+
13
17
  license "MIT"
14
18
 
15
19
  dependency "rsdl", "~> 0.1"
16
- dependency "rubysdl", "~> 2.2"
20
+
21
+ base = "/data/www/docs.seattlerb.org"
22
+ rdoc_locations << "docs-push.seattlerb.org:#{base}/#{remote_rdoc_dir}"
17
23
  end
18
24
 
19
- task :demos do
25
+ task :demos => :compile do
20
26
  Dir["examples/*.rb"].each do |script|
21
27
  puts script
22
28
  system "rsdl -Ilib #{script}"
@@ -6,8 +6,6 @@ require "graphics"
6
6
  class Boid < Graphics::Body
7
7
  COUNT = 50
8
8
 
9
- AA = SDL::Surface::TRANSFORM_AA
10
-
11
9
  PCT_DAMPENER = 0.01
12
10
  TOO_CLOSE = 50
13
11
  MAX_VELOCITY = 5
@@ -32,7 +30,7 @@ class Boid < Graphics::Body
32
30
  def draw
33
31
  # the blit looks HORRIBLE when rotated... dunno why
34
32
  w.circle x, y, @@max_distance, :gray if w.visual_debug?
35
- w.blit w.body_img, x, y, 0, AA
33
+ w.blit w.body_img, x, y
36
34
  w.angle x, y, a, 3 * m, :red
37
35
  end
38
36
 
@@ -254,8 +252,6 @@ class Boids < Graphics::Simulation
254
252
  def initialize
255
253
  super 850, 850, 16, "Boid"
256
254
 
257
- SDL::Key.enable_key_repeat 500, 250
258
-
259
255
  self.visual_debug = false
260
256
 
261
257
  self.boids = populate Boid
@@ -265,22 +261,17 @@ class Boids < Graphics::Simulation
265
261
  end
266
262
  end
267
263
 
264
+ def initialize_keys
265
+ super
266
+
267
+ add_key_handler(:D) { self.visual_debug = ! visual_debug }
268
+ add_key_handler(:B) { Boid.max_distance += 5 }
269
+ add_key_handler(:S) { Boid.max_distance -= 5 }
270
+ end
271
+
268
272
  def update n
269
273
  boids.each(&:update)
270
274
  self.boids.each(&:wrap)
271
- # sleep 0.1
272
- end
273
-
274
- def handle_event e, n
275
- case e
276
- when SDL::Event::KeyDown then
277
- self.visual_debug = ! visual_debug if SDL::Key.press? SDL::Key::D
278
-
279
- Boid.max_distance += 5 if SDL::Key.press? SDL::Key::B
280
- Boid.max_distance -= 5 if SDL::Key.press? SDL::Key::S
281
- else
282
- super
283
- end
284
275
  end
285
276
 
286
277
  def draw n
@@ -12,11 +12,16 @@ class Ball < Graphics::Body
12
12
  def initialize w
13
13
  super
14
14
 
15
- self.a = rand 180
16
- self.m = rand 100
15
+ self.a = random_angle / 2
16
+ self.m = rand 25
17
17
  self.g = G
18
18
  end
19
19
 
20
+ def draw
21
+ w.angle x, y, a, 10+3*m, :red
22
+ w.circle x, y, 5, :white, :filled
23
+ end
24
+
20
25
  def update
21
26
  fall
22
27
  move
@@ -26,18 +31,6 @@ class Ball < Graphics::Body
26
31
  def fall
27
32
  self.velocity += g
28
33
  end
29
-
30
- def label
31
- l = "%.1f %.1f" % dx_dy
32
- w.text l, x-10, y-40, :white
33
- end
34
-
35
- def draw
36
- # w.angle x, y, a, 3*m, :red
37
- w.angle x, y, a, 50, :red
38
- w.circle x, y, 5, :white, :filled
39
- # label
40
- end
41
34
  end
42
35
 
43
36
  class BounceSimulation < Graphics::Simulation
@@ -49,6 +42,12 @@ class BounceSimulation < Graphics::Simulation
49
42
  self.bs = populate Ball
50
43
  end
51
44
 
45
+ def initialize_keys
46
+ super
47
+ add_key_handler :SPACE, &:randomize
48
+ add_key_handler :R, &:reverse
49
+ end
50
+
52
51
  def update n
53
52
  bs.each(&:update)
54
53
  end
@@ -56,20 +55,13 @@ class BounceSimulation < Graphics::Simulation
56
55
  def draw n
57
56
  clear
58
57
  bs.each(&:draw)
59
- bs.first.label
60
58
  fps n
61
59
  end
62
60
 
63
- def handle_keys
64
- super
65
- randomize if SDL::Key.press? SDL::Key::SPACE
66
- reverse if SDL::Key.press? SDL::Key::R
67
- end
68
-
69
61
  def randomize
70
62
  bs.each do |b|
71
- b.m = rand(100)
72
- b.a = rand(180)
63
+ b.m = rand(25)
64
+ b.a = b.random_angle / 2
73
65
  end
74
66
  end
75
67
 
@@ -0,0 +1,75 @@
1
+ #!/usr/local/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "graphics"
5
+
6
+ class Demo < Graphics::Simulation
7
+ attr_accessor :woot, :menlo32
8
+ attr_accessor :rct
9
+
10
+ def initialize
11
+ super 801, 801
12
+
13
+ self.font = find_font("Menlo", 16)
14
+ self.menlo32 = find_font("Menlo", 32)
15
+
16
+ self.woot = render_text "woot", :black, menlo32
17
+
18
+ self.rct = sprite 50, 25 do
19
+ rect 0, 0, 49, 24, :blue # TODO: can't be black?!?
20
+ end
21
+ end
22
+
23
+ def update n
24
+ end
25
+
26
+ L = Math.sqrt(200*200 + 100*100)
27
+ A = R2D*Math.atan2(200, 100)
28
+
29
+ def draw n
30
+ clear :white
31
+
32
+ (0..90).step(30) do |deg|
33
+ shift = (woot.h*Math.sin(D2R*deg))
34
+ put woot, 400-shift, 300, deg
35
+ end
36
+ text "woot", 400, 300, :red, menlo32
37
+
38
+ rect 550, 100, 50, 50, :blue, :filled
39
+ rect 575, 125, 50, 50, :blue
40
+
41
+ ellipse 550, 200, 50, 25, :red
42
+ ellipse 550, 250, 50, 25, :red, :filled
43
+
44
+ angle 50, 50, 90, 25, :blue
45
+
46
+ (0..w).step(100) do |x|
47
+ vline x, :red
48
+ text x.to_s, x+5, 5, :black
49
+ end
50
+
51
+ (0..h).step(100) do |y|
52
+ hline y, :green
53
+ text y.to_s, 5, y+5, :black
54
+ end
55
+
56
+ circle 200, 200, 100, :blue
57
+ text "circle 200, 200, 100, :blue", 100, 200, :black
58
+
59
+ bezier 400, 400, 450, 700, 550, 300, 600, 600, :blue
60
+ text "bezier 400, 400, 450, 700, 550, 300, 600, 600, :blue", 200, 400, :black
61
+
62
+ angle 200, 500, A, L, :black
63
+ text "angle 200, 500, %.2f, %.2f, :black" % [A, L], 100, 500, :black
64
+
65
+ (0..90).step(30).each do |deg|
66
+ put rct, 500-(rct.h*Math.sin(D2R*deg)), 600, deg
67
+ angle 500, 600, deg, 50, :red
68
+
69
+ blit rct, 600, 600, deg
70
+ angle 600, 600, deg, 50, :red
71
+ end
72
+ end
73
+ end
74
+
75
+ Demo.new.run if $0 == __FILE__
@@ -28,21 +28,21 @@ class Sprite < Graphics::Body
28
28
  end
29
29
 
30
30
  def collide_with? other
31
- w.cmap.collision_check(x, y, w.cmap, other.x, other.y) != nil
31
+ w.cmap.check(x, y, w.cmap, other.x, other.y)
32
32
  end
33
33
  end
34
34
 
35
35
  class Collision < Graphics::Simulation
36
- attr_accessor :sprites, :cmap, :image
36
+ attr_accessor :sprites, :cmap, :tank_img
37
37
 
38
38
  def initialize
39
39
  super 850, 850, 16, "Collision"
40
40
 
41
- self.image = SDL::Surface.load "resources/images/body.png"
42
- self.cmap = image.make_collision_map
41
+ self.tank_img = image "resources/images/body.png"
42
+ self.cmap = tank_img.make_collision_map
43
43
 
44
44
  self.sprites = populate Sprite do |s|
45
- s.image = image
45
+ s.image = tank_img
46
46
  end
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ class Collision < Graphics::Simulation
50
50
  "<Screen ...>"
51
51
  end
52
52
 
53
- def detect_collisions(sprites)
53
+ def detect_collisions sprites
54
54
  collisions = []
55
55
  sprites.combination(2).each do |a, b|
56
56
  collisions << a << b if a.collide_with? b