texplay 0.4.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG +222 -0
  3. data/README.markdown +48 -0
  4. data/Rakefile +16 -0
  5. data/examples/common.rb +18 -0
  6. data/examples/example_alpha_blend.rb +29 -0
  7. data/examples/example_bezier.rb +41 -0
  8. data/examples/example_blank.rb +37 -0
  9. data/examples/example_cache.rb +21 -0
  10. data/examples/example_color_control.rb +69 -0
  11. data/examples/example_color_transform.rb +62 -0
  12. data/examples/example_color_transform_circle.rb +34 -0
  13. data/examples/example_darken.rb +24 -0
  14. data/examples/example_dup.rb +73 -0
  15. data/examples/example_each.rb +39 -0
  16. data/examples/example_effect.rb +34 -0
  17. data/examples/example_fill.rb +43 -0
  18. data/examples/example_fill_old.rb +48 -0
  19. data/examples/example_fluent.rb +29 -0
  20. data/examples/example_font.rb +31 -0
  21. data/examples/example_hash_arguments.rb +46 -0
  22. data/examples/example_ippa.rb +23 -0
  23. data/examples/example_light.rb +75 -0
  24. data/examples/example_light_multiply.rb +18 -0
  25. data/examples/example_lsystem.rb +61 -0
  26. data/examples/example_melt.rb +25 -0
  27. data/examples/example_meyet.rb +62 -0
  28. data/examples/example_polyline.rb +42 -0
  29. data/examples/example_scale.rb +27 -0
  30. data/examples/example_select.rb +36 -0
  31. data/examples/example_select2.rb +25 -0
  32. data/examples/example_simple.rb +46 -0
  33. data/examples/example_splice.rb +26 -0
  34. data/examples/example_sync.rb +59 -0
  35. data/examples/example_tiles.rb +41 -0
  36. data/examples/example_trace.rb +22 -0
  37. data/examples/example_transparent.rb +28 -0
  38. data/examples/example_transparent2.rb +24 -0
  39. data/examples/example_transparent3.rb +20 -0
  40. data/examples/example_turtle.rb +39 -0
  41. data/examples/example_weird.rb +22 -0
  42. data/examples/example_window_render_to_image.rb +41 -0
  43. data/examples/example_window_to_blob.rb +35 -0
  44. data/examples/media/bird.png +0 -0
  45. data/examples/media/body.png +0 -0
  46. data/examples/media/empty2.png +0 -0
  47. data/examples/media/face.png +0 -0
  48. data/examples/media/gob.png +0 -0
  49. data/examples/media/gosu.png +0 -0
  50. data/examples/media/green.png +0 -0
  51. data/examples/media/logo.png +0 -0
  52. data/examples/media/maria.png +0 -0
  53. data/examples/media/object.png +0 -0
  54. data/examples/media/rose.bmp +0 -0
  55. data/examples/media/sand1.png +0 -0
  56. data/examples/media/sunset.png +0 -0
  57. data/examples/media/texplay.png +0 -0
  58. data/ext/texplay/actions.c +1006 -0
  59. data/ext/texplay/actions.h +60 -0
  60. data/ext/texplay/bindings.c +1125 -0
  61. data/ext/texplay/bindings.h +46 -0
  62. data/ext/texplay/cache.c +118 -0
  63. data/ext/texplay/cache.h +24 -0
  64. data/ext/texplay/compat.h +27 -0
  65. data/ext/texplay/extconf.rb +38 -0
  66. data/ext/texplay/graphics_utils.c +1313 -0
  67. data/ext/texplay/graphics_utils.h +22 -0
  68. data/ext/texplay/texplay.c +201 -0
  69. data/ext/texplay/texplay.h +153 -0
  70. data/ext/texplay/utils.c +891 -0
  71. data/ext/texplay/utils.h +153 -0
  72. data/ext/texplay/vendor/freeglut/include/GL/freeglut.h +22 -0
  73. data/ext/texplay/vendor/freeglut/include/GL/freeglut_ext.h +236 -0
  74. data/ext/texplay/vendor/freeglut/include/GL/freeglut_std.h +628 -0
  75. data/ext/texplay/vendor/freeglut/include/GL/glut.h +21 -0
  76. data/lib/texplay-contrib.rb +147 -0
  77. data/lib/texplay.rb +347 -0
  78. data/lib/texplay/1.8/texplay.so +0 -0
  79. data/lib/texplay/1.9/texplay.so +0 -0
  80. data/lib/texplay/alone.rb +20 -0
  81. data/lib/texplay/c_function_docs.rb +178 -0
  82. data/lib/texplay/live.rb +84 -0
  83. data/lib/texplay/version.rb +3 -0
  84. data/live/live.rb +85 -0
  85. data/test/image_spec.rb +45 -0
  86. data/test/texplay_spec.rb +144 -0
  87. metadata +179 -0
@@ -0,0 +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
@@ -0,0 +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
+
@@ -0,0 +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
+
@@ -0,0 +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
@@ -0,0 +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
+
@@ -0,0 +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
+
@@ -0,0 +1,42 @@
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}/empty2.png")
9
+
10
+ # put a border on the image
11
+ @img.rect 0,0, @img.width - 1, @img.height - 1
12
+
13
+ points = []
14
+
15
+ # NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
16
+ 10.times {
17
+ p = TexPlay::TPPoint.new
18
+ p.x = @img.width * rand
19
+ p.y = @img.height * rand
20
+
21
+ points << p
22
+ }
23
+
24
+
25
+ # what if we want to turn a polyline into a polygon?
26
+ @img.polyline points, :closed => true, :color => :blue
27
+ @img.polyline points, :color => :red
28
+ end
29
+
30
+ def draw
31
+
32
+ # NOTE: (when viewing) the blue line is the extra line added to close the polygon,
33
+ # red lines are original polyline
34
+ @img.draw 0, 0,1
35
+ end
36
+
37
+ end
38
+
39
+
40
+ w = W.new
41
+ w.show
42
+
@@ -0,0 +1,27 @@
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}/logo.png")
9
+ @img2 = TexPlay::create_blank_image(self, 500, 500)
10
+
11
+ @img2.splice_and_scale @img, 0, 50, :factor => 2
12
+ @img2.splice @img, 0, 200
13
+ end
14
+
15
+ def draw
16
+ x = @img.width * rand
17
+ y = @img.height * rand
18
+
19
+ @img2.draw 100, 100,1
20
+ end
21
+
22
+ end
23
+
24
+
25
+ w = W.new
26
+ w.show
27
+
@@ -0,0 +1,36 @@
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
+
9
+ # draw a filled rect with left region blue, and right region red
10
+ # at top and yellow at bottom
11
+ @img = TexPlay.create_image(self, 500, 500, :color => Gosu::Color::BLUE)
12
+ @img.rect 250,0, 500, 500, :color => :red, :fill => true
13
+ @img.rect 250, 250, 500, 500, :color => :yellow, :fill => true
14
+
15
+ # base rect is green on left and purple on right
16
+ @base = TexPlay.create_image(self, 500, 500, :color => :green)
17
+ @base.rect 250,0, 500, 500, :color => :purple, :fill => true
18
+
19
+ # splice @img into @base, and select the yellow part of @img to
20
+ # go into the purple part of @base
21
+ # a combination of source_select
22
+ # and dest_select - filtering both source and destination pixels
23
+ @base.splice @img, 0, 0, :dest_select => :purple, :source_select => :yellow
24
+
25
+ end
26
+
27
+ def draw
28
+ @base.draw 0, 0,1
29
+ end
30
+
31
+ end
32
+
33
+
34
+ w = W.new
35
+ w.show
36
+
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+ require 'benchmark'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(500, 500, false, 20)
9
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
10
+ @maria = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
11
+ @img.rect 0,0, @img.width - 1, @img.height - 1
12
+ @img.splice @maria, 0, 0, :tolerance => 0.70, :source_select => [:brown,:yellow], :crop => [200, 50, 500, 800]
13
+
14
+ end
15
+
16
+ def draw
17
+ @img.draw 0, 0,1
18
+ end
19
+
20
+ end
21
+
22
+
23
+ w = W.new
24
+ w.show
25
+
@@ -0,0 +1,46 @@
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}/empty2.png")
9
+ @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
10
+
11
+ # put a border on the image
12
+ @img.rect 0,0, @img.width - 1, @img.height - 1, :color => 0xffff00ff, :fill => true
13
+
14
+ # perform some e drawing actions
15
+ @img.line 0,0, @img.width - 1, @img.height - 1, :color => Gosu::Color::AQUA
16
+ @img.circle 400, 100, 40, :fill => true, :color => [rand, rand, rand, 1]
17
+ @img.rect 200, 300, 300, 400, :fill => true, :color => :red, :source_ignore => [:green],
18
+ :color_control => proc {
19
+ rand(2) == 1 ? :red : :blue
20
+ }
21
+
22
+ @img.ngon 400,300,50, 5, :start_angle => 90
23
+ @img.ngon 300,300,50, 5, :start_angle => 45
24
+
25
+ # NOTE: chroma_key means NOT to splice in that color (pixels with that color are skipped)
26
+ # (chroma_key_not does the opposite, it skips pixels that do NOT have that color)
27
+ @img.splice @gosu, 210, 330,
28
+ :dest_select => [:blue], :source_ignore => [:alpha, :green]
29
+
30
+ @img.line 200, 300, 300, 400, :thickness => 5,
31
+ :dest_select => :blue, :dest_ignore => :red
32
+
33
+ puts (@img.get_pixel 2000, 310).inspect
34
+ puts @img.get_pixel 2000, 310, :color_mode => :gosu
35
+ end
36
+
37
+ def draw
38
+ @img.draw 100, 50,1
39
+ end
40
+
41
+ end
42
+
43
+
44
+ w = W.new
45
+ w.show
46
+