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,3 +1,3 @@
1
- module TexPlay
2
- VERSION = "0.3.5"
3
- end
1
+ module TexPlay
2
+ VERSION = "0.4"
3
+ end
data/live/live.rb CHANGED
@@ -1,85 +1,85 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'rubygems'
4
- require "#{direc}/../lib/texplay"
5
- require 'pry'
6
-
7
- WIDTH = 640
8
- HEIGHT = 480
9
-
10
- class Gosu::Image
11
- attr_accessor :x, :y
12
-
13
- alias_method :orig_init, :initialize
14
- def initialize(*args)
15
- @x = WIDTH / 2
16
- @y = HEIGHT / 2
17
- orig_init(*args)
18
- end
19
- end
20
-
21
- class WinClass < Gosu::Window
22
-
23
- class View
24
- attr_accessor :zoom, :rotate
25
-
26
- def initialize
27
- @zoom = 1
28
- @rotate = 0
29
- end
30
-
31
- def reset
32
- @zoom = 1
33
- @rotate = 0
34
- end
35
- end
36
-
37
- attr_reader :images, :view
38
-
39
- def initialize
40
- super(WIDTH, HEIGHT, false)
41
- Gosu.enable_undocumented_retrofication
42
-
43
- @images = []
44
- @view = View.new
45
- @pry_instance = Pry.new :prompt => [Proc.new { "(live)> " }, Proc.new { "(live)* " }]
46
-
47
- @img = TexPlay.create_image(self, 200, 200)
48
- @img.rect 0, 0, @img.width - 1, @img.height - 1
49
-
50
- images << @img
51
- @binding = binding
52
- end
53
-
54
- def create_image(width, height, options={})
55
- TexPlay.create_image(self, width, height, options)
56
- end
57
-
58
- def load_image(file)
59
- Gosu::Image.new(self, file)
60
- end
61
-
62
- def show_image(image)
63
- images << image
64
- end
65
-
66
- def hide_image(image)
67
- images.delete(image)
68
- end
69
-
70
- def draw
71
- images.uniq!
72
- images.each do |v|
73
- v.draw_rot(v.x, v.y, 1, view.rotate, 0.5, 0.5, view.zoom, view.zoom)
74
- end
75
- end
76
-
77
- def update
78
- @pry_instance.rep(@binding)
79
- end
80
- end
81
-
82
- w = WinClass.new
83
-
84
- w.show
85
-
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/texplay"
5
+ require 'pry'
6
+
7
+ WIDTH = 640
8
+ HEIGHT = 480
9
+
10
+ class Gosu::Image
11
+ attr_accessor :x, :y
12
+
13
+ alias_method :orig_init, :initialize
14
+ def initialize(*args)
15
+ @x = WIDTH / 2
16
+ @y = HEIGHT / 2
17
+ orig_init(*args)
18
+ end
19
+ end
20
+
21
+ class WinClass < Gosu::Window
22
+
23
+ class View
24
+ attr_accessor :zoom, :rotate
25
+
26
+ def initialize
27
+ @zoom = 1
28
+ @rotate = 0
29
+ end
30
+
31
+ def reset
32
+ @zoom = 1
33
+ @rotate = 0
34
+ end
35
+ end
36
+
37
+ attr_reader :images, :view
38
+
39
+ def initialize
40
+ super(WIDTH, HEIGHT, false)
41
+ Gosu.enable_undocumented_retrofication
42
+
43
+ @images = []
44
+ @view = View.new
45
+ @pry_instance = Pry.new :prompt => [Proc.new { "(live)> " }, Proc.new { "(live)* " }]
46
+
47
+ @img = TexPlay.create_image(self, 200, 200)
48
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
49
+
50
+ images << @img
51
+ @binding = binding
52
+ end
53
+
54
+ def create_image(width, height, options={})
55
+ TexPlay.create_image(self, width, height, options)
56
+ end
57
+
58
+ def load_image(file)
59
+ Gosu::Image.new(self, file)
60
+ end
61
+
62
+ def show_image(image)
63
+ images << image
64
+ end
65
+
66
+ def hide_image(image)
67
+ images.delete(image)
68
+ end
69
+
70
+ def draw
71
+ images.uniq!
72
+ images.each do |v|
73
+ v.draw_rot(v.x, v.y, 1, view.rotate, 0.5, 0.5, view.zoom, view.zoom)
74
+ end
75
+ end
76
+
77
+ def update
78
+ @pry_instance.rep(@binding)
79
+ end
80
+ end
81
+
82
+ w = WinClass.new
83
+
84
+ w.show
85
+
data/test/image_spec.rb CHANGED
@@ -1,45 +1,45 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require "#{direc}/../lib/texplay"
4
-
5
- class Module
6
- public :remove_const
7
- end
8
-
9
- describe Gosu::Image do
10
- before do
11
- @window = Gosu::Window.new(640, 480, false)
12
- NormalImageSize = [Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2]
13
- TooLargeImageSize = [2000, 2000]
14
- end
15
-
16
- after do
17
- Object.remove_const(:NormalImageSize)
18
- Object.remove_const(:TooLargeImageSize)
19
- end
20
-
21
- describe "Gosu::Image#new (patched by TexPlay)" do
22
- describe "caching option" do
23
- it "should not cache image if :caching => false" do
24
- source_image = TexPlay.create_image(@window, *NormalImageSize)
25
- source_image.quad_cached?.should == false
26
-
27
- image = Gosu::Image.new(@window, source_image, :caching => false)
28
- image.width.should == NormalImageSize[0]
29
- image.height.should == NormalImageSize[1]
30
-
31
- image.quad_cached?.should == false
32
- end
33
-
34
- it "should cache the image if :caching => true" do
35
- source_image = TexPlay.create_image(@window, *NormalImageSize)
36
-
37
- image = Gosu::Image.new(@window, source_image, :caching => true)
38
- image.width.should == NormalImageSize[0]
39
- image.height.should == NormalImageSize[1]
40
-
41
- image.quad_cached?.should == true
42
- end
43
- end
44
- end
45
- end
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require "#{direc}/../lib/texplay"
4
+
5
+ class Module
6
+ public :remove_const
7
+ end
8
+
9
+ describe Gosu::Image do
10
+ before do
11
+ @window = Gosu::Window.new(640, 480, false)
12
+ NormalImageSize = [Gosu::MAX_TEXTURE_SIZE - 2, Gosu::MAX_TEXTURE_SIZE - 2]
13
+ TooLargeImageSize = [2000, 2000]
14
+ end
15
+
16
+ after do
17
+ Object.remove_const(:NormalImageSize)
18
+ Object.remove_const(:TooLargeImageSize)
19
+ end
20
+
21
+ describe "Gosu::Image#new (patched by TexPlay)" do
22
+ describe "caching option" do
23
+ it "should not cache image if :caching => false" do
24
+ source_image = TexPlay.create_image(@window, *NormalImageSize)
25
+ source_image.quad_cached?.should == false
26
+
27
+ image = Gosu::Image.new(@window, source_image, :caching => false)
28
+ image.width.should == NormalImageSize[0]
29
+ image.height.should == NormalImageSize[1]
30
+
31
+ image.quad_cached?.should == false
32
+ end
33
+
34
+ it "should cache the image if :caching => true" do
35
+ source_image = TexPlay.create_image(@window, *NormalImageSize)
36
+
37
+ image = Gosu::Image.new(@window, source_image, :caching => true)
38
+ image.width.should == NormalImageSize[0]
39
+ image.height.should == NormalImageSize[1]
40
+
41
+ image.quad_cached?.should == true
42
+ end
43
+ end
44
+ end
45
+ end
data/test/texplay_spec.rb CHANGED
@@ -1,141 +1,144 @@
1
- $LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
2
- direc = File.dirname(__FILE__)
3
-
4
- require "#{direc}/../lib/texplay"
5
-
6
- describe TexPlay do
7
- described_class = TexPlay
8
-
9
- before do
10
- @window = Gosu::Window.new(640, 480, false)
11
- end
12
-
13
- describe "#create_image" do
14
- it "should create a blank image of the correct size" do
15
- width, height = 30, 10
16
- image = described_class.create_image(@window, width, height)
17
-
18
- image.width.should == width
19
- image.height.should == height
20
-
21
- width.times do |x|
22
- height.times do |y|
23
- image.get_pixel(x, y).should == [0.0, 0.0, 0.0, 0.0]
24
- end
25
- end
26
- end
27
-
28
- it "should create a coloured image of the correct size" do
29
- width, height = 10, 30
30
- color = [1.0, 1.0, 0.0, 1.0]
31
- image = described_class.create_image(@window, width, height, :color => color)
32
-
33
- image.width.should == width
34
- image.height.should == height
35
-
36
- width.times do |x|
37
- height.times do |y|
38
- image.get_pixel(x, y).should == color
39
- end
40
- end
41
- end
42
-
43
- it "should raise an error if an image dimension is 0 or less" do
44
- lambda { described_class.create_image(@window, 0, 0)}.should.raise ArgumentError
45
- end
46
-
47
- # TODO: Should probably be an ArgumentError.
48
- it "should NOT raise an error if the image would be too large (as uses raw blobs, doesnt use TexPlay at all)" do
49
- too_big = TexPlay::TP_MAX_QUAD_SIZE + 1
50
- [[too_big, 5], [10, too_big], [too_big, too_big]].each do |width, height|
51
- lambda { described_class.create_image(@window, width, height)}.should.not.raise Exception
52
- end
53
- end
54
- end
55
-
56
- describe "#clear" do
57
- it "should clear an image to the correct color" do
58
- img = described_class.create_image(@window, 10, 10)
59
- img.clear :color => :red
60
- (0...img.width).each do |x|
61
- (0...img.height).each do |y|
62
- img.get_pixel(x,y).should == [1,0,0,1]
63
- end
64
- end
65
- end
66
- end
67
-
68
- describe "#from_blob" do
69
- # it "should create an image with the requested pixel data and size" do
70
- # # 4 x 3, with columns of red, blue, green, transparent.
71
- # gosu_colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0, 0, 0, 0]]
72
- # texplay_colors = gosu_colors.map {|a| a.map {|c| c / 255.0 } }
73
- # width, height = gosu_colors.size, 3
74
-
75
- # image = described_class.from_blob(@window, (gosu_colors * height).flatten.pack('C*'), width, height)
76
-
77
- # image.width.should == width
78
- # image.height.should == height
79
-
80
- # texplay_colors.each_with_index do |color, x|
81
- # 3.times do |y|
82
- # image.get_pixel(x, y).should == color
83
- # end
84
- # end
85
- # end
86
-
87
- it "should raise an error if the image size is not correct for the blob data" do
88
- lambda { described_class.from_blob(@window, [1, 1, 1, 1].pack("C*"), 2, 1) }.should.raise ArgumentError
89
- end
90
-
91
- it "should raise an error if an image dimension is 0 or less" do
92
- lambda { described_class.from_blob(@window, '', 0, 0) }.should.raise ArgumentError
93
- end
94
- end
95
-
96
- describe "alpha_blend" do
97
- it "should alpha blend using source alpha and not fixing alpha" do
98
- img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
99
- img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
100
- img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
101
- end
102
-
103
- it "hash params true and :source should be equivalent" do
104
- img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
105
- img2 = img1.dup
106
- img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
107
- img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => true
108
-
109
- img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
110
- img2.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
111
- end
112
-
113
- it "false or nil should prevent alpha blending" do
114
- img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
115
- img2 = img1.dup
116
- img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => false
117
- img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => nil
118
-
119
- img1.get_pixel(5, 5).should == [0, 0, 1, 0.5]
120
- img2.get_pixel(5, 5).should == [0, 0, 1, 0.5]
121
- end
122
-
123
- it "should alpha blend using dest alpha and not fixing alpha" do
124
- img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
125
- img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest
126
- img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
127
- end
128
-
129
- it "should alpha blend using source alpha and fixing alpha" do
130
- img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
131
- img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source_with_fixed_alpha
132
- img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 1]
133
- end
134
-
135
- it "should alpha blend using dest alpha and fixing alpha" do
136
- img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
137
- img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest_with_fixed_alpha
138
- img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.5]
139
- end
140
- end
141
- end
1
+ $LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..', 'lib','texplay')
2
+ direc = File.dirname(__FILE__)
3
+
4
+ require "#{direc}/../lib/texplay"
5
+
6
+ describe TexPlay do
7
+ described_class = TexPlay
8
+
9
+ before do
10
+ @window = Gosu::Window.new(640, 480, false)
11
+ end
12
+
13
+ describe "#create_image" do
14
+ it "should create a blank image of the correct size" do
15
+ width, height = 30, 10
16
+ image = described_class.create_image(@window, width, height)
17
+
18
+ image.width.should == width
19
+ image.height.should == height
20
+
21
+ width.times do |x|
22
+ height.times do |y|
23
+ image.get_pixel(x, y).should == [0.0, 0.0, 0.0, 0.0]
24
+ end
25
+ end
26
+ end
27
+
28
+ it "should create a coloured image of the correct size" do
29
+ width, height = 10, 30
30
+ color = [1.0, 1.0, 0.0, 1.0]
31
+ image = described_class.create_image(@window, width, height, :color => color)
32
+
33
+ image.width.should == width
34
+ image.height.should == height
35
+
36
+ width.times do |x|
37
+ height.times do |y|
38
+ image.get_pixel(x, y).should == color
39
+ end
40
+ end
41
+ end
42
+
43
+ it "should raise an error if an image dimension is 0 or less" do
44
+ lambda { described_class.create_image(@window, 0, 0)}.should raise_error(ArgumentError)
45
+ end
46
+
47
+ # TODO: Should probably be an ArgumentError.
48
+ it "should raise an ArgumentError if the image would be too large" do
49
+ too_big = TexPlay::TP_MAX_QUAD_SIZE + 1
50
+ [[too_big, 5], [10, too_big], [too_big, too_big]].each do |width, height|
51
+ puts "WIDTH: #{width.inspect}, HEIGHT: #{height.inspect}"
52
+ lambda {
53
+ described_class.create_image(@window, width, height)
54
+ }.should raise_error(ArgumentError)
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#clear" do
60
+ it "should clear an image to the correct color" do
61
+ img = described_class.create_image(@window, 10, 10)
62
+ img.clear :color => :red
63
+ (0...img.width).each do |x|
64
+ (0...img.height).each do |y|
65
+ img.get_pixel(x,y).should == [1,0,0,1]
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#from_blob" do
72
+ # it "should create an image with the requested pixel data and size" do
73
+ # # 4 x 3, with columns of red, blue, green, transparent.
74
+ # gosu_colors = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], [0, 0, 0, 0]]
75
+ # texplay_colors = gosu_colors.map {|a| a.map {|c| c / 255.0 } }
76
+ # width, height = gosu_colors.size, 3
77
+
78
+ # image = described_class.from_blob(@window, (gosu_colors * height).flatten.pack('C*'), width, height)
79
+
80
+ # image.width.should == width
81
+ # image.height.should == height
82
+
83
+ # texplay_colors.each_with_index do |color, x|
84
+ # 3.times do |y|
85
+ # image.get_pixel(x, y).should == color
86
+ # end
87
+ # end
88
+ # end
89
+
90
+ it "should raise an error if the image size is not correct for the blob data" do
91
+ lambda { described_class.from_blob(@window, [1, 1, 1, 1].pack("C*"), 2, 1) }.should raise_error(ArgumentError)
92
+ end
93
+
94
+ it "should raise an error if an image dimension is 0 or less" do
95
+ lambda { described_class.from_blob(@window, '', 0, 0) }.should raise_error(ArgumentError)
96
+ end
97
+ end
98
+
99
+ describe "alpha_blend" do
100
+ it "should alpha blend using source alpha and not fixing alpha" do
101
+ img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
102
+ img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
103
+ img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
104
+ end
105
+
106
+ it "hash params true and :source should be equivalent" do
107
+ img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
108
+ img2 = img1.dup
109
+ img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source
110
+ img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => true
111
+
112
+ img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
113
+ img2.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
114
+ end
115
+
116
+ it "false or nil should prevent alpha blending" do
117
+ img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
118
+ img2 = img1.dup
119
+ img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => false
120
+ img2.clear :color => [0, 0, 1, 0.5], :alpha_blend => nil
121
+
122
+ img1.get_pixel(5, 5).should == [0, 0, 1, 0.5]
123
+ img2.get_pixel(5, 5).should == [0, 0, 1, 0.5]
124
+ end
125
+
126
+ it "should alpha blend using dest alpha and not fixing alpha" do
127
+ img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
128
+ img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest
129
+ img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.75]
130
+ end
131
+
132
+ it "should alpha blend using source alpha and fixing alpha" do
133
+ img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 1]
134
+ img1.clear :color => [0, 0, 1, 0.5], :alpha_blend => :source_with_fixed_alpha
135
+ img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 1]
136
+ end
137
+
138
+ it "should alpha blend using dest alpha and fixing alpha" do
139
+ img1 = described_class.create_image(@window, 10, 10).clear :color => [1, 0, 0, 0.5]
140
+ img1.clear :color => [0, 0, 1, 1], :alpha_blend => :dest_with_fixed_alpha
141
+ img1.get_pixel(5, 5).should == [0.5, 0, 0.5, 0.5]
142
+ end
143
+ end
144
+ end