texplay 0.2.800 → 0.2.900

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG +138 -119
  2. data/README.markdown +43 -41
  3. data/Rakefile +68 -68
  4. data/examples/common.rb +8 -8
  5. data/examples/example_alpha_blend.rb +31 -31
  6. data/examples/example_bezier.rb +42 -42
  7. data/examples/example_color_control.rb +69 -69
  8. data/examples/example_color_transform.rb +64 -67
  9. data/examples/example_color_transform_circle.rb +65 -0
  10. data/examples/example_dup.rb +75 -75
  11. data/examples/example_each.rb +42 -42
  12. data/examples/example_effect.rb +35 -35
  13. data/examples/example_fill.rb +44 -44
  14. data/examples/example_fill_old.rb +49 -49
  15. data/examples/example_fluent.rb +31 -31
  16. data/examples/example_gen_eval.rb +34 -34
  17. data/examples/example_hash_arguments.rb +47 -47
  18. data/examples/example_light.rb +77 -0
  19. data/examples/example_lsystem.rb +61 -61
  20. data/examples/example_melt.rb +27 -27
  21. data/examples/example_meyet.rb +64 -0
  22. data/examples/example_polyline.rb +43 -43
  23. data/examples/example_scale.rb +29 -29
  24. data/examples/example_simple.rb +48 -38
  25. data/examples/example_sync.rb +60 -60
  26. data/examples/example_trace.rb +1 -1
  27. data/examples/example_turtle.rb +40 -40
  28. data/examples/example_weird.rb +3 -1
  29. data/examples/media/Thumbs.db +0 -0
  30. data/ext/texplay/actions.c +999 -1001
  31. data/ext/texplay/actions.h +60 -60
  32. data/ext/texplay/bindings.c +1162 -1149
  33. data/ext/texplay/bindings.h +46 -46
  34. data/ext/texplay/cache.c +118 -118
  35. data/ext/texplay/cache.h +24 -24
  36. data/ext/texplay/compat.h +27 -27
  37. data/ext/texplay/extconf.rb +28 -28
  38. data/ext/texplay/gen_eval.c +211 -211
  39. data/ext/texplay/gen_eval.h +20 -20
  40. data/ext/texplay/graphics_utils.c +188 -63
  41. data/ext/texplay/graphics_utils.h +0 -1
  42. data/ext/texplay/object2module.c +171 -171
  43. data/ext/texplay/object2module.h +11 -11
  44. data/ext/texplay/texplay.c +169 -169
  45. data/ext/texplay/texplay.h +147 -130
  46. data/ext/texplay/utils.c +816 -752
  47. data/ext/texplay/utils.h +151 -145
  48. data/lib/texplay-contrib.rb +171 -171
  49. data/lib/texplay.rb +162 -137
  50. data/lib/texplay/version.rb +1 -1
  51. metadata +9 -5
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+
8
+ # TEST_CASE 1 shows 2 pieces of text, but the background is black, even with :chroma_key. TEST_CASE 2 shows nothing.
9
+ # However, if you remove the :chroma_key's, you see a black background (and no text) in TEST_CASE 2, so there, :chroma_key appears to work.
10
+ TEST_CASE = 1 # 1 shows everything, 2 shows nothing. Both, however, should show everything, and haev a working :chroma_key => :alpha
11
+ SYNC_TEST = false # Setting to true enables a force_sync.. but no matter where that is placed, it doesn't help
12
+
13
+ class Wnd < Gosu::Window
14
+ def initialize
15
+ super(500, 200, false)
16
+ self.caption = "Splice Issues"
17
+
18
+ @chrome = TexPlay::create_blank_image(self, 200, 200)
19
+ @chrome.fill 0, 0, :color => :purple
20
+ @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
21
+ @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
22
+ @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
23
+ @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
24
+
25
+ @chrome3 = @chrome.dup if TEST_CASE == 2
26
+
27
+ @short_text = Gosu::Image.from_text(self, "text", Gosu::default_font_name, 20)
28
+ @long_text = Gosu::Image.from_text(self, "This is a long piece of text..", Gosu::default_font_name, 20)
29
+
30
+ @chrome2 = @chrome.dup if TEST_CASE == 1
31
+
32
+ @chrome.splice @short_text, 5, 5, :alpha_blend => true
33
+ @chrome.splice @long_text, 5, 105, :alpha_blend => true
34
+ puts @long_text.get_pixel(2,2)
35
+
36
+ if TEST_CASE == 1
37
+ @chrome2.splice @short_text, 105, 5, :alpha_blend => true
38
+ @chrome2.splice @long_text, 105, 105, :alpha_blend => true
39
+ elsif TEST_CASE == 2
40
+ @chrome3.splice @short_text, 105, 5, :alpha_blend => true
41
+ @chrome3.splice @long_text, 105, 105, :alpha_blend => true
42
+ end
43
+ end
44
+
45
+ def draw
46
+ @chrome.draw(0,0,1)
47
+ @chrome2.draw(200,0,1) if TEST_CASE == 1
48
+ @chrome3.draw(400,0,1) if TEST_CASE == 2
49
+ end
50
+
51
+ def draw_text
52
+ @chrome.splice @short_text, 5, 40, :alpha_blend => true # Chroma key apparently doesn't work either..
53
+ @chrome2.splice @short_text, 5, 40, :alpha_blend => true if TEST_CASE == 1
54
+ @chrome3.splice @short_text, 5, 40, :alpha_blend => true if TEST_CASE == 2
55
+ end
56
+
57
+ def button_down(id)
58
+ close if id == Gosu::KbEscape
59
+ draw_text if id == Gosu::KbSpace
60
+ end
61
+ end
62
+
63
+ Wnd.new.show
64
+
@@ -1,43 +1,43 @@
1
- require 'rubygems'
2
- require 'common'
3
- require 'texplay'
4
-
5
-
6
- class W < Gosu::Window
7
- def initialize
8
- super(1024, 768, false, 20)
9
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
-
11
- # put a border on the image
12
- @img.rect 0,0, @img.width - 1, @img.height - 1
13
-
14
- points = []
15
-
16
- # NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
17
- 10.times {
18
- p = TexPlay::TPPoint.new
19
- p.x = @img.width * rand
20
- p.y = @img.height * rand
21
-
22
- points << p
23
- }
24
-
25
-
26
- # what if we want to turn a polyline into a polygon?
27
- @img.polyline points, :closed => true, :color => :blue
28
- @img.polyline points, :color => :red
29
- end
30
-
31
- def draw
32
-
33
- # NOTE: (when viewing) the blue line is the extra line added to close the polygon,
34
- # red lines are original polyline
35
- @img.draw 100, 50,1
36
- end
37
-
38
- end
39
-
40
-
41
- w = W.new
42
- w.show
43
-
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
+
11
+ # put a border on the image
12
+ @img.rect 0,0, @img.width - 1, @img.height - 1
13
+
14
+ points = []
15
+
16
+ # NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
17
+ 10.times {
18
+ p = TexPlay::TPPoint.new
19
+ p.x = @img.width * rand
20
+ p.y = @img.height * rand
21
+
22
+ points << p
23
+ }
24
+
25
+
26
+ # what if we want to turn a polyline into a polygon?
27
+ @img.polyline points, :closed => true, :color => :blue
28
+ @img.polyline points, :color => :red
29
+ end
30
+
31
+ def draw
32
+
33
+ # NOTE: (when viewing) the blue line is the extra line added to close the polygon,
34
+ # red lines are original polyline
35
+ @img.draw 100, 50,1
36
+ end
37
+
38
+ end
39
+
40
+
41
+ w = W.new
42
+ w.show
43
+
@@ -1,29 +1,29 @@
1
- require 'rubygems'
2
- require 'common'
3
- require 'gosu'
4
- require 'texplay'
5
-
6
-
7
- class W < Gosu::Window
8
- def initialize
9
- super(1024, 768, false, 20)
10
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/logo.png")
11
- @img2 = TexPlay::create_blank_image(self, 500, 500)
12
-
13
- @img2.splice_and_scale @img, 0, 50, :factor => 2
14
- @img2.splice @img, 0, 200
15
- end
16
-
17
- def draw
18
- x = @img.width * rand
19
- y = @img.height * rand
20
-
21
- @img2.draw 100, 100,1
22
- end
23
-
24
- end
25
-
26
-
27
- w = W.new
28
- w.show
29
-
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+ class W < Gosu::Window
8
+ def initialize
9
+ super(1024, 768, false, 20)
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/logo.png")
11
+ @img2 = TexPlay::create_blank_image(self, 500, 500)
12
+
13
+ @img2.splice_and_scale @img, 0, 50, :factor => 2
14
+ @img2.splice @img, 0, 200
15
+ end
16
+
17
+ def draw
18
+ x = @img.width * rand
19
+ y = @img.height * rand
20
+
21
+ @img2.draw 100, 100,1
22
+ end
23
+
24
+ end
25
+
26
+
27
+ w = W.new
28
+ w.show
29
+
@@ -1,38 +1,48 @@
1
- require 'rubygems'
2
- require 'common'
3
- require 'gosu'
4
- require 'texplay'
5
-
6
-
7
- class W < Gosu::Window
8
- def initialize
9
- super(1024, 768, false, 20)
10
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
11
- @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
12
-
13
- # put a border on the image
14
- @img.rect 0,0, @img.width - 1, @img.height - 1
15
-
16
- # perform some simple drawing actions
17
- @img.line 0,0, @img.width - 1, @img.height - 1, :color => :yellow
18
- @img.circle 400, 100, 40, :fill => true, :color => [rand, rand, rand, 1]
19
- @img.rect 200, 300, 300, 400, :fill => true, :color => :red
20
-
21
- @img.ngon 400,300,50, 5, :start_angle => 90
22
- @img.ngon 300,300,50, 5, :start_angle => 45
23
-
24
- # NOTE: chroma_key means NOT to splice in that color (pixels with that color are skipped)
25
- # (chroma_key_not does the opposite, it skips pixels that do NOT have that color)
26
- @img.splice @gosu, 210, 330, :chroma_key => :alpha
27
- end
28
-
29
- def draw
30
- @img.draw 100, 50,1
31
- end
32
-
33
- end
34
-
35
-
36
- w = W.new
37
- w.show
38
-
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+ class W < Gosu::Window
8
+ def initialize
9
+ super(500, 500, false, 20)
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
11
+ @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
12
+
13
+ # put a border on the image
14
+ @img.rect 0,0, @img.width - 1, @img.height - 1, :color => Gosu::Color::CYAN
15
+
16
+ # perform some simple drawing actions
17
+ @img.line 0,0, @img.width - 1, @img.height - 1, :color => Gosu::Color::AQUA
18
+ @img.circle 400, 100, 40, :fill => true, :color => [rand, rand, rand, 1]
19
+ @img.rect 200, 300, 300, 400, :fill => true, :color => :red, :source_ignore => [:green],
20
+ :color_control => proc {
21
+ rand(2) == 1 ? :red : :blue
22
+ }
23
+
24
+ @img.ngon 400,300,50, 5, :start_angle => 90
25
+ @img.ngon 300,300,50, 5, :start_angle => 45
26
+
27
+ # NOTE: chroma_key means NOT to splice in that color (pixels with that color are skipped)
28
+ # (chroma_key_not does the opposite, it skips pixels that do NOT have that color)
29
+ @img.splice @gosu, 210, 330,
30
+ :dest_select => [:blue], :source_ignore => [:alpha, :green]
31
+
32
+ @img.line 200, 300, 300, 400, :thickness => 5,
33
+ :dest_select => :blue, :dest_ignore => :red
34
+
35
+ puts @img.get_pixel 200, 310
36
+ puts @img.get_pixel 200, 310, :color_mode => :gosu
37
+ end
38
+
39
+ def draw
40
+ @img.draw 100, 50,1
41
+ end
42
+
43
+ end
44
+
45
+
46
+ w = W.new
47
+ w.show
48
+
@@ -1,60 +1,60 @@
1
- require 'rubygems'
2
- require 'common'
3
- require 'texplay'
4
-
5
-
6
- class W < Gosu::Window
7
- def initialize
8
- super(1024, 768, false, 20)
9
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
-
11
- # sets the 'global' color for all actions in this image
12
- @img.color :red
13
-
14
- # let's draw the circle without syncing it to gl
15
- @img.circle 100, 100, 50, :fill => true, :sync_mode => :no_sync
16
-
17
- # now let's sync half of it to gl
18
- @img.force_sync [100, 50, 150, 150]
19
-
20
- # let's draw some lazy shapes
21
- @img.set_options :sync_mode => :lazy_sync
22
-
23
- @img.ngon 200, 300, 40, 5, :color => :red
24
- @img.ngon 280, 300, 40, 6, :color => :green
25
- @img.ngon 360, 300, 40, 7, :color => :blue
26
-
27
- # now let's sync the lazy shapes to gl
28
- @img.paint
29
-
30
- # NOTE: the lazy drawing (above) is identical to using the following paint block
31
- # @img.paint {
32
- # ngon 200, 300, 50, 5
33
- # ...etc
34
- # }
35
-
36
- # end lazy drawing mode
37
- @img.delete_options
38
-
39
- # the default sync mode is eager_sync
40
- # in this mode actions are drawn and sync'd immediately
41
- # NOTE: TexPlay only syncs the part of the image that changed to gl
42
- @img.ngon 440, 300, 40, 8, :color => :tyrian
43
-
44
- # paint blocks can also accept a sync_mode parameter
45
- # NOTE: the line below will not be visible until you
46
- # explictly sync it to gl; probably using @img.force_sync
47
- @img.paint(:sync_mode => :no_sync) {
48
- line 0, 0, @img.width, @img.height
49
- }
50
- end
51
-
52
- def draw
53
-
54
- @img.draw 100, 50,1
55
- end
56
- end
57
-
58
- w = W.new
59
- w.show
60
-
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
+
11
+ # sets the 'global' color for all actions in this image
12
+ @img.color :red
13
+
14
+ # let's draw the circle without syncing it to gl
15
+ @img.circle 100, 100, 50, :fill => true, :sync_mode => :no_sync
16
+
17
+ # now let's sync half of it to gl
18
+ @img.force_sync [100, 50, 150, 150]
19
+
20
+ # let's draw some lazy shapes
21
+ @img.set_options :sync_mode => :lazy_sync
22
+
23
+ @img.ngon 200, 300, 40, 5, :color => :red
24
+ @img.ngon 280, 300, 40, 6, :color => :green
25
+ @img.ngon 360, 300, 40, 7, :color => :blue
26
+
27
+ # now let's sync the lazy shapes to gl
28
+ @img.paint
29
+
30
+ # NOTE: the lazy drawing (above) is identical to using the following paint block
31
+ # @img.paint {
32
+ # ngon 200, 300, 50, 5
33
+ # ...etc
34
+ # }
35
+
36
+ # end lazy drawing mode
37
+ @img.delete_options
38
+
39
+ # the default sync mode is eager_sync
40
+ # in this mode actions are drawn and sync'd immediately
41
+ # NOTE: TexPlay only syncs the part of the image that changed to gl
42
+ @img.ngon 440, 300, 40, 8, :color => :tyrian
43
+
44
+ # paint blocks can also accept a sync_mode parameter
45
+ # NOTE: the line below will not be visible until you
46
+ # explictly sync it to gl; probably using @img.force_sync
47
+ @img.paint(:sync_mode => :no_sync) {
48
+ line 0, 0, @img.width, @img.height
49
+ }
50
+ end
51
+
52
+ def draw
53
+
54
+ @img.draw 100, 50,1
55
+ end
56
+ end
57
+
58
+ w = W.new
59
+ w.show
60
+
@@ -8,7 +8,7 @@ class W < Gosu::Window
8
8
  super(1024, 768, false, 20)
9
9
  @img = TexPlay.create_image(self, 500, 500).fill(3,3, :color => :alpha)
10
10
  @img.rect 100, 100, 300 , 300, :color => :blue, :fill => true
11
- puts (@img.line 0,0, 100, 100, :trace => { :until_color => :blue }).inspect
11
+ puts (@img.line 400, 200, 100, 200, :trace => { :until_color => :blue }).inspect
12
12
  end
13
13
 
14
14
  def draw
@@ -1,40 +1,40 @@
1
- require 'rubygems'
2
- require 'common'
3
- require 'texplay'
4
-
5
-
6
- class W < Gosu::Window
7
- def initialize
8
- super(1024, 768, false, 20)
9
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
-
11
- # put a border on the image
12
- @img.rect 0, 0, @img.width - 1, @img.height - 1
13
-
14
- @length = 0
15
- end
16
-
17
-
18
- # NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
19
- def draw
20
-
21
- # NOTE: putting actions in paint block means they are only sync'd to gl at end of block.
22
- # compare to calling an action directly (on an @img) where it is sync'd to gl immediately
23
-
24
- @img.paint {
25
-
26
- # a 2nd arg of 'true' means to show the turtle
27
- forward(@length, true, :color => :red)
28
- turn(89.5)
29
- @length += 2
30
- }
31
-
32
- @img.draw 100, 50,1
33
- end
34
-
35
- end
36
-
37
-
38
- w = W.new
39
- w.show
40
-
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
+
11
+ # put a border on the image
12
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
13
+
14
+ @length = 0
15
+ end
16
+
17
+
18
+ # NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
19
+ def draw
20
+
21
+ # NOTE: putting actions in paint block means they are only sync'd to gl at end of block.
22
+ # compare to calling an action directly (on an @img) where it is sync'd to gl immediately
23
+
24
+ @img.paint {
25
+
26
+ # a 2nd arg of 'true' means to show the turtle
27
+ forward(@length, true, :color => :red)
28
+ turn(89.5)
29
+ @length += 2
30
+ }
31
+
32
+ @img.draw 100, 50,1
33
+ end
34
+
35
+ end
36
+
37
+
38
+ w = W.new
39
+ w.show
40
+