texplay 0.3.5 → 0.4

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.
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,41 +1,41 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class Gosu::Image
5
- # so we can use the old TexPlay to_blob -- appears to segfault?!
6
- undef_method :to_blob
7
- end
8
-
9
- class W < Gosu::Window
10
- def initialize
11
- super(500, 300, false, 20)
12
- @spritesheet = Gosu::Image.new(self, "#{Common::MEDIA}/body.png", false)
13
- @spritesheet.splice(Gosu::Image.new(self, "#{Common::MEDIA}/face.png", false), 0,0, :alpha_blend => true)
14
- @sprite_array = Gosu::Image::load_tiles(self, @spritesheet, 40, 80, false)
15
- end
16
-
17
- def draw
18
- @spritesheet.draw(200,200,0)
19
- # @sprite_array[0].draw(200,200,0)
20
- end
21
-
22
- end
23
-
24
-
25
- w = W.new
26
- w.show
27
-
28
-
29
- # require 'rubygems'
30
- # require 'gosu'
31
- # require 'texplay'
32
- # class Game_Window < Gosu::Window
33
- # def initialize
34
- # super(500, 400, false)
35
- # self.caption = "Image Test"
36
- # end
37
-
38
- # def draw
39
- # end
40
-
41
- # end
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class Gosu::Image
5
+ # so we can use the old TexPlay to_blob -- appears to segfault?!
6
+ undef_method :to_blob
7
+ end
8
+
9
+ class W < Gosu::Window
10
+ def initialize
11
+ super(500, 300, false, 20)
12
+ @spritesheet = Gosu::Image.new(self, "#{Common::MEDIA}/body.png", false)
13
+ @spritesheet.splice(Gosu::Image.new(self, "#{Common::MEDIA}/face.png", false), 0,0, :alpha_blend => true)
14
+ @sprite_array = Gosu::Image::load_tiles(self, @spritesheet, 40, 80, false)
15
+ end
16
+
17
+ def draw
18
+ @spritesheet.draw(200,200,0)
19
+ # @sprite_array[0].draw(200,200,0)
20
+ end
21
+
22
+ end
23
+
24
+
25
+ w = W.new
26
+ w.show
27
+
28
+
29
+ # require 'rubygems'
30
+ # require 'gosu'
31
+ # require 'texplay'
32
+ # class Game_Window < Gosu::Window
33
+ # def initialize
34
+ # super(500, 400, false)
35
+ # self.caption = "Image Test"
36
+ # end
37
+
38
+ # def draw
39
+ # end
40
+
41
+ # end
@@ -1,22 +1,22 @@
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 = TexPlay.create_image(self, 500, 500).fill(3,3, :color => :alpha)
9
- @img.rect 100, 100, 300 , 300, :color => :blue, :fill => true
10
- puts (@img.line 498, 200, 600, 200, :trace => { :while_color => :blue })
11
- end
12
-
13
- def draw
14
- @img.draw 100, 50,1
15
- end
16
-
17
- end
18
-
19
-
20
- w = W.new
21
- w.show
22
-
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 = TexPlay.create_image(self, 500, 500).fill(3,3, :color => :alpha)
9
+ @img.rect 100, 100, 300 , 300, :color => :blue, :fill => true
10
+ puts (@img.line 498, 200, 600, 200, :trace => { :while_color => :blue })
11
+ end
12
+
13
+ def draw
14
+ @img.draw 100, 50,1
15
+ end
16
+
17
+ end
18
+
19
+
20
+ w = W.new
21
+ w.show
22
+
@@ -1,28 +1,28 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class W < Gosu::Window
5
- def initialize
6
- super(400, 300, false, 20)
7
- @img = TexPlay.create_image(self, 400, 300)
8
- @img.rect 100, 100, 200, 200, :color => :red, :fill => true
9
-
10
- # Coloured transparent block with white border.
11
- @img.rect 200, 100, 300, 200, :color => [1, 1, 1, 0], :fill => true
12
- @img.rect 200, 100, 300, 200
13
-
14
- @img.line 0, 120, 500, 120, :dest_select => :transparent, :color => :green
15
- # @img.line 0, 140, 500, 140, :dest_select => :alpha
16
- # @img.line 0, 160, 500, 160, :dest_select => :transparent # Should draw everywhere except the red block.
17
- # @img.line 0, 180, 500, 180, :dest_ignore => :transparent # Should draw only on the red block.
18
- end
19
-
20
- def draw
21
- @img.draw 0, 0, 1
22
- end
23
-
24
- end
25
-
26
-
27
- w = W.new
28
- w.show
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class W < Gosu::Window
5
+ def initialize
6
+ super(400, 300, false, 20)
7
+ @img = TexPlay.create_image(self, 400, 300)
8
+ @img.rect 100, 100, 200, 200, :color => :red, :fill => true
9
+
10
+ # Coloured transparent block with white border.
11
+ @img.rect 200, 100, 300, 200, :color => [1, 1, 1, 0], :fill => true
12
+ @img.rect 200, 100, 300, 200
13
+
14
+ @img.line 0, 120, 500, 120, :dest_select => :transparent, :color => :green
15
+ # @img.line 0, 140, 500, 140, :dest_select => :alpha
16
+ # @img.line 0, 160, 500, 160, :dest_select => :transparent # Should draw everywhere except the red block.
17
+ # @img.line 0, 180, 500, 180, :dest_ignore => :transparent # Should draw only on the red block.
18
+ end
19
+
20
+ def draw
21
+ @img.draw 0, 0, 1
22
+ end
23
+
24
+ end
25
+
26
+
27
+ w = W.new
28
+ w.show
@@ -1,24 +1,24 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class W < Gosu::Window
5
- def initialize
6
- super(400, 300, false, 20)
7
- @img = TexPlay.create_image(self, 400, 300)
8
- @img.rect 0, 0, 200, 100, :color => [1,1,1,0], :fill => true
9
- @img.rect 200, 100, 400, 300, :color => [1,1,1,0.1], :fill => true
10
-
11
-
12
- @img.line 0, 120, 500, 120,
13
- :dest_select => :transparent, :color => :green, :tolerance => 0.1
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
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class W < Gosu::Window
5
+ def initialize
6
+ super(400, 300, false, 20)
7
+ @img = TexPlay.create_image(self, 400, 300)
8
+ @img.rect 0, 0, 200, 100, :color => [1,1,1,0], :fill => true
9
+ @img.rect 200, 100, 400, 300, :color => [1,1,1,0.1], :fill => true
10
+
11
+
12
+ @img.line 0, 120, 500, 120,
13
+ :dest_select => :transparent, :color => :green, :tolerance => 0.1
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
@@ -1,20 +1,20 @@
1
- $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
- require 'common'
3
-
4
- class W < Gosu::Window
5
- def initialize
6
- super(400, 300, false, 20)
7
- @img = Gosu::Image.new(self, "#{Common::MEDIA}/object.png")
8
-
9
- @img.rect 0, 0, 200, 100, :color => :green, :fill => true, :dest_select => :transparent, :tolerance => 0.5
10
- end
11
-
12
- def draw
13
- @img.draw 100, 100, 1
14
- end
15
-
16
- end
17
-
18
-
19
- w = W.new
20
- w.show
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+ class W < Gosu::Window
5
+ def initialize
6
+ super(400, 300, false, 20)
7
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/object.png")
8
+
9
+ @img.rect 0, 0, 200, 100, :color => :green, :fill => true, :dest_select => :transparent, :tolerance => 0.5
10
+ end
11
+
12
+ def draw
13
+ @img.draw 100, 100, 1
14
+ end
15
+
16
+ end
17
+
18
+
19
+ w = W.new
20
+ w.show
@@ -1,39 +1,39 @@
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
- @length = 0
14
- end
15
-
16
-
17
- # NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
18
- def draw
19
-
20
- # NOTE: putting actions in paint block means they are only sync'd to gl at end of block.
21
- # compare to calling an action directly (on an @img) where it is sync'd to gl immediately
22
-
23
- @img.paint {
24
-
25
- # a 2nd arg of 'true' means to show the turtle
26
- forward(@length, true, :color => :red)
27
- turn(89.5)
28
- @length += 2
29
- }
30
-
31
- @img.draw 0, 0,1
32
- end
33
-
34
- end
35
-
36
-
37
- w = W.new
38
- w.show
39
-
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
+ @length = 0
14
+ end
15
+
16
+
17
+ # NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
18
+ def draw
19
+
20
+ # NOTE: putting actions in paint block means they are only sync'd to gl at end of block.
21
+ # compare to calling an action directly (on an @img) where it is sync'd to gl immediately
22
+
23
+ @img.paint {
24
+
25
+ # a 2nd arg of 'true' means to show the turtle
26
+ forward(@length, true, :color => :red)
27
+ turn(89.5)
28
+ @length += 2
29
+ }
30
+
31
+ @img.draw 0, 0,1
32
+ end
33
+
34
+ end
35
+
36
+
37
+ w = W.new
38
+ w.show
39
+
@@ -1,22 +1,22 @@
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}/gob.png")
9
- @img.rect 0, 0, @img.width - 1, @img.height - 1
10
- puts @img.line 1,1, 1, @img.height - 1, :trace => { :while_color => :alpha }
11
-
12
-
13
- end
14
-
15
- def draw
16
- @img.draw 50, 50,1
17
- end
18
- end
19
-
20
- w = W.new
21
- w.show
22
-
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}/gob.png")
9
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
10
+ puts @img.line 1,1, 1, @img.height - 1, :trace => { :while_color => :alpha }
11
+
12
+
13
+ end
14
+
15
+ def draw
16
+ @img.draw 50, 50,1
17
+ end
18
+ end
19
+
20
+ w = W.new
21
+ w.show
22
+
@@ -1,41 +1,41 @@
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)
7
- self.caption = "Press <escape> to render to texture"
8
-
9
- @picture = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
10
- @block_image = TexPlay.create_image(self, 10, 10, :color => Gosu::Color::RED)
11
- @rendered_image = TexPlay.create_image(self, Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2, :color => :purple)
12
-
13
- @display = false
14
- end
15
-
16
- def update
17
-
18
- end
19
-
20
- def draw
21
- # Render the image once.
22
- if button_down?(Gosu::KbEscape) and not @display
23
-
24
- render_to_image(@rendered_image, :clip_to => [40, 20, 440, 320]) do
25
- @picture.draw 0, 0, 1
26
- 1000.times { @block_image.draw rand(250), rand(250), 1, 1, 1, Gosu::Color.new(rand(255), rand(255), rand(255), rand(255)) }
27
- (0..width).step(5) {|x| draw_line 0, 0, Gosu::Color.new(255, 0, 0, 0), x, width, Gosu::Color.new(255, 0, 0, 0), 1 }
28
- end
29
- @display = true
30
- end
31
-
32
- # Display it indefinitely after that.
33
- @rendered_image.draw(10, 10, 0) if @display
34
- end
35
-
36
- end
37
-
38
-
39
- w = W.new
40
- w.show
41
-
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)
7
+ self.caption = "Press <escape> to render to texture"
8
+
9
+ @picture = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
10
+ @block_image = TexPlay.create_image(self, 10, 10, :color => Gosu::Color::RED)
11
+ @rendered_image = TexPlay.create_image(self, Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2, :color => :purple)
12
+
13
+ @display = false
14
+ end
15
+
16
+ def update
17
+
18
+ end
19
+
20
+ def draw
21
+ # Render the image once.
22
+ if button_down?(Gosu::KbEscape) and not @display
23
+
24
+ render_to_image(@rendered_image, :clip_to => [40, 20, 440, 320]) do
25
+ @picture.draw 0, 0, 1
26
+ 1000.times { @block_image.draw rand(250), rand(250), 1, 1, 1, Gosu::Color.new(rand(255), rand(255), rand(255), rand(255)) }
27
+ (0..width).step(5) {|x| draw_line 0, 0, Gosu::Color.new(255, 0, 0, 0), x, width, Gosu::Color.new(255, 0, 0, 0), 1 }
28
+ end
29
+ @display = true
30
+ end
31
+
32
+ # Display it indefinitely after that.
33
+ @rendered_image.draw(10, 10, 0) if @display
34
+ end
35
+
36
+ end
37
+
38
+
39
+ w = W.new
40
+ w.show
41
+