texplay 0.3.5 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +222 -222
  2. data/README.markdown +43 -43
  3. data/Rakefile +3 -99
  4. data/examples/common.rb +18 -18
  5. data/examples/example_alpha_blend.rb +29 -29
  6. data/examples/example_bezier.rb +41 -41
  7. data/examples/example_blank.rb +37 -37
  8. data/examples/example_cache.rb +21 -21
  9. data/examples/example_color_control.rb +69 -69
  10. data/examples/example_color_transform.rb +62 -62
  11. data/examples/example_color_transform_circle.rb +34 -34
  12. data/examples/example_darken.rb +24 -24
  13. data/examples/example_dup.rb +73 -73
  14. data/examples/example_each.rb +39 -39
  15. data/examples/example_effect.rb +34 -34
  16. data/examples/example_fill.rb +43 -43
  17. data/examples/example_fill_old.rb +48 -48
  18. data/examples/example_fluent.rb +29 -29
  19. data/examples/example_font.rb +31 -31
  20. data/examples/example_hash_arguments.rb +46 -46
  21. data/examples/example_ippa.rb +23 -23
  22. data/examples/example_light.rb +75 -75
  23. data/examples/example_light_multiply.rb +18 -18
  24. data/examples/example_lsystem.rb +61 -61
  25. data/examples/example_melt.rb +25 -25
  26. data/examples/example_meyet.rb +62 -62
  27. data/examples/example_polyline.rb +42 -42
  28. data/examples/example_scale.rb +27 -27
  29. data/examples/example_select.rb +36 -36
  30. data/examples/example_select2.rb +25 -25
  31. data/examples/example_simple.rb +46 -46
  32. data/examples/example_splice.rb +26 -26
  33. data/examples/example_sync.rb +59 -59
  34. data/examples/example_tiles.rb +41 -41
  35. data/examples/example_trace.rb +22 -22
  36. data/examples/example_transparent.rb +28 -28
  37. data/examples/example_transparent2.rb +24 -24
  38. data/examples/example_transparent3.rb +20 -20
  39. data/examples/example_turtle.rb +39 -39
  40. data/examples/example_weird.rb +22 -22
  41. data/examples/example_window_render_to_image.rb +41 -41
  42. data/examples/example_window_to_blob.rb +35 -35
  43. data/examples/media/maria.png +0 -0
  44. data/examples/media/rose.bmp +0 -0
  45. data/ext/texplay/actions.c +1006 -1006
  46. data/ext/texplay/actions.h +60 -60
  47. data/ext/texplay/bindings.c +1125 -1186
  48. data/ext/texplay/bindings.h +46 -46
  49. data/ext/texplay/cache.c +118 -118
  50. data/ext/texplay/cache.h +24 -24
  51. data/ext/texplay/compat.h +27 -27
  52. data/ext/texplay/extconf.rb +28 -28
  53. data/ext/texplay/graphics_utils.c +1313 -1313
  54. data/ext/texplay/graphics_utils.h +22 -22
  55. data/ext/texplay/texplay.c +201 -216
  56. data/ext/texplay/texplay.h +153 -153
  57. data/ext/texplay/utils.c +891 -891
  58. data/ext/texplay/utils.h +153 -153
  59. data/lib/texplay-contrib.rb +147 -164
  60. data/lib/texplay.rb +341 -356
  61. data/lib/texplay/alone.rb +20 -20
  62. data/lib/texplay/c_function_docs.rb +178 -190
  63. data/lib/texplay/live.rb +84 -84
  64. data/lib/texplay/version.rb +3 -3
  65. data/live/live.rb +85 -85
  66. data/test/image_spec.rb +45 -45
  67. data/test/texplay_spec.rb +144 -141
  68. metadata +54 -42
  69. data/examples/example_gen_eval.rb +0 -32
  70. data/ext/texplay/gen_eval.c +0 -211
  71. data/ext/texplay/gen_eval.h +0 -20
  72. data/ext/texplay/object2module.c +0 -171
  73. data/ext/texplay/object2module.h +0 -11
@@ -1,23 +1,23 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class Window < Gosu::Window
5
- def initialize
6
- super(500, 500, false, 20)
7
-
8
- @image = TexPlay.create_image(self, 50, 50)
9
-
10
- from_x = 50
11
- from_y = 50
12
- to_x = 51
13
- to_y = 51
14
-
15
- x2, y2, color = @image.line from_x, from_y, to_x, to_y, :trace => { :while_color => :red }
16
-
17
- p x2
18
- p y2
19
- p color
20
- end
21
- end
22
-
23
- Window.new.show
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class Window < Gosu::Window
5
+ def initialize
6
+ super(500, 500, false, 20)
7
+
8
+ @image = TexPlay.create_image(self, 50, 50)
9
+
10
+ from_x = 50
11
+ from_y = 50
12
+ to_x = 51
13
+ to_y = 51
14
+
15
+ x2, y2, color = @image.line from_x, from_y, to_x, to_y, :trace => { :while_color => :red }
16
+
17
+ p x2
18
+ p y2
19
+ p color
20
+ end
21
+ end
22
+
23
+ Window.new.show
@@ -1,75 +1,75 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class W < Gosu::Window
5
- def initialize
6
- super(500, 500, false, 20)
7
-
8
- @x1 = 10
9
- @x2 = 200
10
- @y1 = 10
11
- @y2 = 10
12
-
13
- @radius = 100.0
14
- @inner = 20.0
15
- @max_opacity = 0.5
16
- @max_opacity2 = 0.5
17
-
18
- penumbra = (@radius - @inner).to_i
19
-
20
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
21
- #@img.rect(0, 0, @img.width - 1, @img.height - 1, :fill => true)
22
-
23
- @circ2 = TexPlay.create_image(self, @radius * 2, @radius * 2)
24
-
25
- @circ1 = TexPlay.create_image(self, @radius * 2, @radius * 2)
26
-
27
-
28
- shading_step = @max_opacity2.to_f / penumbra.to_f
29
- @radius.to_i.downto(@inner) { |r|
30
- @circ1.circle @radius, @radius, r, :color => [1, 0, 0, ((@radius - r) * shading_step)],
31
- :fill => true
32
- }
33
-
34
- @circ1.circle @radius, @radius, @inner, :color => [1, 0, 0, @max_opacity2], :fill => true
35
-
36
- shading_step = @max_opacity.to_f / penumbra.to_f
37
- @radius.to_i.downto(@inner) { |r|
38
- @circ2.circle @radius, @radius, r, :color => [0, 0, 1, ((@radius - r) * shading_step)],
39
- :fill => true
40
- }
41
-
42
- @circ2.circle @radius, @radius, @inner, :color => [0, 0, 1, @max_opacity], :fill => true
43
- end
44
-
45
- def draw
46
- @x1 += 1
47
- @y1 += 1
48
-
49
- @x2 -= 1
50
- @y2 += 1
51
-
52
-
53
-
54
- @img.draw 10, 10,1
55
- @circ1.draw @x1, @y1,1
56
- @circ2.draw @x2, @y1,1
57
-
58
- if button_down?(Gosu::KbEscape)
59
- IL.Enable(IL::ORIGIN_SET)
60
- IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
61
- # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
62
- exit
63
- end
64
-
65
- end
66
-
67
- def update
68
- end
69
-
70
- end
71
-
72
-
73
- w = W.new
74
- w.show
75
-
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class W < Gosu::Window
5
+ def initialize
6
+ super(500, 500, false, 20)
7
+
8
+ @x1 = 10
9
+ @x2 = 200
10
+ @y1 = 10
11
+ @y2 = 10
12
+
13
+ @radius = 100.0
14
+ @inner = 20.0
15
+ @max_opacity = 0.5
16
+ @max_opacity2 = 0.5
17
+
18
+ penumbra = (@radius - @inner).to_i
19
+
20
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
21
+ #@img.rect(0, 0, @img.width - 1, @img.height - 1, :fill => true)
22
+
23
+ @circ2 = TexPlay.create_image(self, @radius * 2, @radius * 2)
24
+
25
+ @circ1 = TexPlay.create_image(self, @radius * 2, @radius * 2)
26
+
27
+
28
+ shading_step = @max_opacity2.to_f / penumbra.to_f
29
+ @radius.to_i.downto(@inner) { |r|
30
+ @circ1.circle @radius, @radius, r, :color => [1, 0, 0, ((@radius - r) * shading_step)],
31
+ :fill => true
32
+ }
33
+
34
+ @circ1.circle @radius, @radius, @inner, :color => [1, 0, 0, @max_opacity2], :fill => true
35
+
36
+ shading_step = @max_opacity.to_f / penumbra.to_f
37
+ @radius.to_i.downto(@inner) { |r|
38
+ @circ2.circle @radius, @radius, r, :color => [0, 0, 1, ((@radius - r) * shading_step)],
39
+ :fill => true
40
+ }
41
+
42
+ @circ2.circle @radius, @radius, @inner, :color => [0, 0, 1, @max_opacity], :fill => true
43
+ end
44
+
45
+ def draw
46
+ @x1 += 1
47
+ @y1 += 1
48
+
49
+ @x2 -= 1
50
+ @y2 += 1
51
+
52
+
53
+
54
+ @img.draw 10, 10,1
55
+ @circ1.draw @x1, @y1,1
56
+ @circ2.draw @x2, @y1,1
57
+
58
+ if button_down?(Gosu::KbEscape)
59
+ IL.Enable(IL::ORIGIN_SET)
60
+ IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
61
+ # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
62
+ exit
63
+ end
64
+
65
+ end
66
+
67
+ def update
68
+ end
69
+
70
+ end
71
+
72
+
73
+ w = W.new
74
+ w.show
75
+
@@ -1,18 +1,18 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class W < Gosu::Window
5
- def initialize
6
- super(500, 500, false, 20)
7
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
8
- @cover = TexPlay.create_image(self, @img.width, @img.height, :color => Gosu::Color.new(127, 127, 127, 127))
9
- end
10
-
11
- def draw
12
- @img.draw 0, 0, 1
13
- @cover.draw 0, 0, 1, 1, 1, Gosu::Color.new(0xffffffff), :multiply
14
- end
15
- end
16
-
17
- W.new.show
18
-
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class W < Gosu::Window
5
+ def initialize
6
+ super(500, 500, false, 20)
7
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
8
+ @cover = TexPlay.create_image(self, @img.width, @img.height, :color => Gosu::Color.new(127, 127, 127, 127))
9
+ end
10
+
11
+ def draw
12
+ @img.draw 0, 0, 1
13
+ @cover.draw 0, 0, 1, 1, 1, Gosu::Color.new(0xffffffff), :multiply
14
+ end
15
+ end
16
+
17
+ W.new.show
18
+
@@ -1,61 +1,61 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- Dragon = TexPlay::LSystem.new do
5
- rule "F" => "F"
6
- rule "X" => "X+YF+"
7
- rule "Y" => "-FX-Y"
8
- angle 90
9
-
10
- atom "FX"
11
- end
12
-
13
- Koch = TexPlay::LSystem.new do
14
- rule "F" => "F-F++F-F"
15
-
16
- angle 60
17
-
18
- atom "F"
19
- end
20
-
21
- Bush1 = TexPlay::LSystem.new do
22
- rule "F" => "F[-F]F[+F][F]"
23
-
24
- angle 20
25
- atom "F"
26
- end
27
-
28
- Bush2 = TexPlay::LSystem.new do
29
- rule "F" => "FF"
30
- rule "X" => "F[+X]F[-X]+X"
31
-
32
- angle 20
33
- atom "X"
34
- end
35
-
36
- Bush3 = TexPlay::LSystem.new do
37
- rule "F" => "FF"
38
- rule "X" => "F-[[X]+X]+F[+FX]-X"
39
-
40
- angle 22.5
41
- atom "X"
42
- end
43
-
44
-
45
-
46
- class W < Gosu::Window
47
- def initialize
48
- super(500, 500, false, 20)
49
- @img = TexPlay::create_blank_image(self, 500, 500)
50
- @img.set_options :color => :rand
51
- @img.lsystem(0, 250, Bush3, :order => 6, :line_length => 4)
52
- #@img.save("dragon.jpg")
53
- end
54
-
55
- def draw
56
- @img.draw(0,0,1)
57
- end
58
- end
59
-
60
- w = W.new
61
- w.show
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ Dragon = TexPlay::LSystem.new do
5
+ rule "F" => "F"
6
+ rule "X" => "X+YF+"
7
+ rule "Y" => "-FX-Y"
8
+ angle 90
9
+
10
+ atom "FX"
11
+ end
12
+
13
+ Koch = TexPlay::LSystem.new do
14
+ rule "F" => "F-F++F-F"
15
+
16
+ angle 60
17
+
18
+ atom "F"
19
+ end
20
+
21
+ Bush1 = TexPlay::LSystem.new do
22
+ rule "F" => "F[-F]F[+F][F]"
23
+
24
+ angle 20
25
+ atom "F"
26
+ end
27
+
28
+ Bush2 = TexPlay::LSystem.new do
29
+ rule "F" => "FF"
30
+ rule "X" => "F[+X]F[-X]+X"
31
+
32
+ angle 20
33
+ atom "X"
34
+ end
35
+
36
+ Bush3 = TexPlay::LSystem.new do
37
+ rule "F" => "FF"
38
+ rule "X" => "F-[[X]+X]+F[+FX]-X"
39
+
40
+ angle 22.5
41
+ atom "X"
42
+ end
43
+
44
+
45
+
46
+ class W < Gosu::Window
47
+ def initialize
48
+ super(500, 500, false, 20)
49
+ @img = TexPlay::create_blank_image(self, 500, 500)
50
+ @img.set_options :color => :rand
51
+ @img.lsystem(0, 250, Bush3, :order => 6, :line_length => 4)
52
+ #@img.save("dragon.jpg")
53
+ end
54
+
55
+ def draw
56
+ @img.draw(0,0,1)
57
+ end
58
+ end
59
+
60
+ w = W.new
61
+ w.show
@@ -1,25 +1,25 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
-
5
- class W < Gosu::Window
6
- def initialize
7
- super(500, 500, false, 20)
8
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
9
- end
10
-
11
- def draw
12
- x = (@img.width - 100/2) * rand
13
- y = (@img.height - 100/2) * rand
14
-
15
- @img.splice @img, x, y + 1, :crop => [x, y, x + 100, y + 100]
16
-
17
- @img.draw 0, 0,1
18
- end
19
-
20
- end
21
-
22
-
23
- w = W.new
24
- w.show
25
-
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+
5
+ class W < Gosu::Window
6
+ def initialize
7
+ super(500, 500, false, 20)
8
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
9
+ end
10
+
11
+ def draw
12
+ x = (@img.width - 100/2) * rand
13
+ y = (@img.height - 100/2) * rand
14
+
15
+ @img.splice @img, x, y + 1, :crop => [x, y, x + 100, y + 100]
16
+
17
+ @img.draw 0, 0,1
18
+ end
19
+
20
+ end
21
+
22
+
23
+ w = W.new
24
+ w.show
25
+
@@ -1,62 +1,62 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
-
5
-
6
- # TEST_CASE 1 shows 2 pieces of text, but the background is black, even with :chroma_key. TEST_CASE 2 shows nothing.
7
- # 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.
8
- TEST_CASE = 1 # 1 shows everything, 2 shows nothing. Both, however, should show everything, and haev a working :chroma_key => :alpha
9
- SYNC_TEST = false # Setting to true enables a force_sync.. but no matter where that is placed, it doesn't help
10
-
11
- class Wnd < Gosu::Window
12
- def initialize
13
- super(500, 200, false)
14
- self.caption = "Splice Issues"
15
-
16
- @chrome = TexPlay::create_blank_image(self, 200, 200)
17
- @chrome.fill 0, 0, :color => :purple
18
- @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
19
- @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
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
-
23
- @chrome3 = @chrome.dup if TEST_CASE == 2
24
-
25
- @short_text = Gosu::Image.from_text(self, "text", Gosu::default_font_name, 20)
26
- @long_text = Gosu::Image.from_text(self, "This is a long piece of text..", Gosu::default_font_name, 20)
27
-
28
- @chrome2 = @chrome.dup if TEST_CASE == 1
29
-
30
- @chrome.splice @short_text, 5, 5, :alpha_blend => true
31
- @chrome.splice @long_text, 5, 105, :alpha_blend => true
32
- puts @long_text.get_pixel(2,2)
33
-
34
- if TEST_CASE == 1
35
- @chrome2.splice @short_text, 105, 5, :alpha_blend => true
36
- @chrome2.splice @long_text, 105, 105, :alpha_blend => true
37
- elsif TEST_CASE == 2
38
- @chrome3.splice @short_text, 105, 5, :alpha_blend => true
39
- @chrome3.splice @long_text, 105, 105, :alpha_blend => true
40
- end
41
- end
42
-
43
- def draw
44
- @chrome.draw(0,0,1)
45
- @chrome2.draw(200,0,1) if TEST_CASE == 1
46
- @chrome3.draw(400,0,1) if TEST_CASE == 2
47
- end
48
-
49
- def draw_text
50
- @chrome.splice @short_text, 5, 40, :alpha_blend => true # Chroma key apparently doesn't work either..
51
- @chrome2.splice @short_text, 5, 40, :alpha_blend => true if TEST_CASE == 1
52
- @chrome3.splice @short_text, 5, 40, :alpha_blend => true if TEST_CASE == 2
53
- end
54
-
55
- def button_down(id)
56
- close if id == Gosu::KbEscape
57
- draw_text if id == Gosu::KbSpace
58
- end
59
- end
60
-
61
- Wnd.new.show
62
-
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+
5
+
6
+ # TEST_CASE 1 shows 2 pieces of text, but the background is black, even with :chroma_key. TEST_CASE 2 shows nothing.
7
+ # 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.
8
+ TEST_CASE = 1 # 1 shows everything, 2 shows nothing. Both, however, should show everything, and haev a working :chroma_key => :alpha
9
+ SYNC_TEST = false # Setting to true enables a force_sync.. but no matter where that is placed, it doesn't help
10
+
11
+ class Wnd < Gosu::Window
12
+ def initialize
13
+ super(500, 200, false)
14
+ self.caption = "Splice Issues"
15
+
16
+ @chrome = TexPlay::create_blank_image(self, 200, 200)
17
+ @chrome.fill 0, 0, :color => :purple
18
+ @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
19
+ @chrome.rect rand(200),rand(200),rand(200),rand(200), :color => :blue
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
+
23
+ @chrome3 = @chrome.dup if TEST_CASE == 2
24
+
25
+ @short_text = Gosu::Image.from_text(self, "text", Gosu::default_font_name, 20)
26
+ @long_text = Gosu::Image.from_text(self, "This is a long piece of text..", Gosu::default_font_name, 20)
27
+
28
+ @chrome2 = @chrome.dup if TEST_CASE == 1
29
+
30
+ @chrome.splice @short_text, 5, 5, :alpha_blend => true
31
+ @chrome.splice @long_text, 5, 105, :alpha_blend => true
32
+ puts @long_text.get_pixel(2,2)
33
+
34
+ if TEST_CASE == 1
35
+ @chrome2.splice @short_text, 105, 5, :alpha_blend => true
36
+ @chrome2.splice @long_text, 105, 105, :alpha_blend => true
37
+ elsif TEST_CASE == 2
38
+ @chrome3.splice @short_text, 105, 5, :alpha_blend => true
39
+ @chrome3.splice @long_text, 105, 105, :alpha_blend => true
40
+ end
41
+ end
42
+
43
+ def draw
44
+ @chrome.draw(0,0,1)
45
+ @chrome2.draw(200,0,1) if TEST_CASE == 1
46
+ @chrome3.draw(400,0,1) if TEST_CASE == 2
47
+ end
48
+
49
+ def draw_text
50
+ @chrome.splice @short_text, 5, 40, :alpha_blend => true # Chroma key apparently doesn't work either..
51
+ @chrome2.splice @short_text, 5, 40, :alpha_blend => true if TEST_CASE == 1
52
+ @chrome3.splice @short_text, 5, 40, :alpha_blend => true if TEST_CASE == 2
53
+ end
54
+
55
+ def button_down(id)
56
+ close if id == Gosu::KbEscape
57
+ draw_text if id == Gosu::KbSpace
58
+ end
59
+ end
60
+
61
+ Wnd.new.show
62
+