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
data/lib/texplay/alone.rb CHANGED
@@ -1,20 +1,20 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require "#{direc}/../texplay"
4
-
5
- module TexPlay
6
- Win = Gosu::Window.new(100, 100, false)
7
-
8
- set_options :sync_mode => :no_sync
9
-
10
- class << self
11
- def load(name)
12
- Gosu::Image.new(Win, name)
13
- end
14
-
15
- alias_method :original_create_image, :create_image
16
- def create_image(width, height, options={})
17
- original_create_image(Win, width, height, options)
18
- end
19
- end
20
- end
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require "#{direc}/../texplay"
4
+
5
+ module TexPlay
6
+ Win = Gosu::Window.new(100, 100, false)
7
+
8
+ set_options :sync_mode => :no_sync
9
+
10
+ class << self
11
+ def load(name)
12
+ Gosu::Image.new(Win, name)
13
+ end
14
+
15
+ alias_method :original_create_image, :create_image
16
+ def create_image(width, height, options={})
17
+ original_create_image(Win, width, height, options)
18
+ end
19
+ end
20
+ end
@@ -1,190 +1,178 @@
1
- # -*- coding: iso-8859-1 -*-
2
- # This code is never run; it is just here so we can document the C functions.
3
-
4
-
5
- module TexPlay
6
- # Draw a bezier curve.
7
- #
8
- # @param (see #polyline)
9
- # @option (see #polyline)
10
- # @return [Gosu::Image]
11
- def bezier(points, options = {})
12
- end
13
-
14
- # Draw a circle.
15
- #
16
- # @note :thickness not implemented for circle.
17
- #
18
- # @param [Number] center_x Horizontal center.
19
- # @param [Number] center_y Vertical center.
20
- # @param [Number] radius Radius.
21
- # @option (see #set_pixel)
22
- # @option options [Boolean] :fill (false) Whether to fill in the shape.
23
- # @option options [Boolean] :filled (false) Synonym for +:fill+
24
- # @return [Gosu::Image]
25
- def circle(center_x, center_y, radius, options = {})
26
- end
27
-
28
- # Make a copy of the image.
29
- #
30
- # @return [Gosu::Image] Deep copy of the image.
31
- def clone()
32
- end
33
-
34
- # (see #clone)
35
- def dup()
36
- end
37
-
38
- # Iterate through every pixel of the image, allowing modification of each pixels.
39
- #
40
- # @yield [color, x, y] Colour and position (arity == 3).
41
- # @yield [color] Colour only (arity == 1).
42
- # @yieldparam [Array<Float>] color RGBA colour array. This can be modified to affect the image directly.
43
- # @yieldparam [Integer] x X position of the pixel.
44
- # @yieldparam [Integer] y Y position of the pixel.
45
- def each(&block)
46
- end
47
-
48
- # Perform a Flood Fill at a given position.
49
- #
50
- # @param [Number] x
51
- # @param [Number] y
52
- # @option options [Gosu::Color, Array<Float>, Symbol] :color (:white) Colour to apply to the drawing action.
53
- # @option options [Proc, Hash] :color_control Effect to apply to the drawing action.
54
- # @return [Gosu::Image]
55
- def fill(x, y, options = {})
56
- end
57
-
58
- # Force synchronisation of the image (send from RAM to VRAM).
59
- #
60
- # @param [Array<Number>] rectangle Area to synchronise.
61
- # @return [Gosu::Image]
62
- def force_sync(rectangle = [0, 0, width, height])
63
- end
64
-
65
- # Get the colour of an individual pixel.
66
- #
67
- # @param [Number] x Horizontal position.
68
- # @param [Number] y Vertical position.
69
- # @return [Array<Float>] 4-element, RGBA colour array.
70
- def get_pixel(x, y)
71
- end
72
-
73
- # @param [Number] x1 X position of start of line.
74
- # @param [Number] y1 Y position of start of line.
75
- # @param [Number] x2 X position of end of line.
76
- # @param [Number] y2 Y position of end of line.
77
- # @option (see #set_pixel)
78
- # @option options [Number] :thickness (1) Thickness of the line.
79
- # @option options [Hash] :trace Trace
80
- # @return [Gosu::Image]
81
- def line(x1, y1, x2, y2, options = {})
82
- end
83
-
84
- # Draw an n-sided polygon.
85
- #
86
- # @param (see #circle)
87
- # @param [Integer] sides Number of sides for the polygon.
88
- # @option (see #circle)
89
- # @return [Gosu::Image]
90
- def ngon(center_x, center_y, radius, sides, options = {})
91
- end
92
-
93
- # Offset all future drawing actions.
94
- #
95
- # The offset is non-stacking.
96
- #
97
- # Can also use +offset(:default)+ to reset offset to (0, 0).
98
- #
99
- # @param [Number] x
100
- # @param [Number] y
101
- # @return [Gosu::Image]
102
- def offset(x, y)
103
- end
104
-
105
- # Perform drawing operations in the context of the image using _lazy_ syncing.
106
- #
107
- # The paint block may look like an ordinary instance_eval, but it is not. The problem that plagues the serious use of
108
- # instance_eval: namely the inability to use local instance variables in the block does not affect the Paint Block.
109
- # This means that code like the following is possible in TexPlay (but impossible with an instance_eval)
110
- #
111
- # How does it work? TexPlay uses an alternative to instance_eval known as gen_eval (http://github.com/banister/gen_eval/tree/master)
112
- # Another peculiarity of paint blocks is how they sync the drawing actions (syncing will be discussed in greater depth
113
- # later on). The drawing actions in a Paint Block are not sync�d until the very end of the Paint Block and are then
114
- # sync'd to video memory all in one go (This style of syncing is called _lazy_ syncing in TexPlay)
115
- #
116
- # @example Drawing to the image within a paint block
117
- # image1.paint do
118
- # circle 10, 10, 20, :color => :green
119
- # bezier [0, 0, 10, 10, 50, 0], :closed => true
120
- # end
121
- #
122
- # @example Showing gen_eval behaviour (can access ivars within the paint block)
123
- # @x = 20
124
- # @y = 30
125
- # my_image.paint do
126
- # circle @x, @y, 20
127
- # end
128
- #
129
- # @option options [Symbol] :sync_mode (:lazy_sync) One of +:lazy_sync+, +:no_sync+ or +:eager_sync+
130
- # @yield Block evaluated as the image.
131
- # @return [Gosu::Image]
132
- def paint(options = {}, &block)
133
- end
134
-
135
- # Draw a series of connected lines.
136
- #
137
- # @param [Array<Number, TPPoint>] points Series of points (either [x1, y1, x2, y2, ...] or [point1, point2]).
138
- # @option (see #rect)
139
- # @option options [Boolean] :closed Whether the last point is linked to the first.
140
- # @return [Gosu::Image]
141
- def polyline(points, options = {})
142
- end
143
-
144
- # Draw a rectangle.
145
- #
146
- # @param [Number] x1 Top of the rectangle.
147
- # @param [Number] y1 Left of the rectangle.
148
- # @param [Number] x2 Right of the rectangle.
149
- # @param [Number] y2 Bottom of the rectangle.
150
- # @option (see #circle)
151
- # @option options [Number] :thickness (1) Thickness of the line.
152
- # @return [Gosu::Image]
153
- def rect(x1, y1, x2, y2, options = {})
154
- end
155
- alias_method :box, :rect
156
-
157
- # Set the colour of an individual pixel.
158
- #
159
- # @param [Number] x
160
- # @param [Number] y
161
- # @option (see #fill)
162
- # @option options [Boolean] :alpha_blend (false) Alpha-blend instead of overwrite.
163
- # @option options [Gosu::Image] :texture Texture to use instead of a flat colour.
164
- # @option options [Symbol] :mode (:copy) Drawing mode to use.
165
- # @return [Gosu::Image]
166
- def set_pixel(x, y, options = {})
167
- end
168
- alias_method :pixel, :set_pixel
169
-
170
- # Copy an image into another image.
171
- #
172
- # @param [Number] x Horizontal position to splice at.
173
- # @param [Number] y Vertical position to splice at.
174
- # @param [Gosu::Image] source Image to copy from.
175
- # @option options [Gosu::Color, Array<Float>, Symbol] :chroma_key Colour to treat as transparent (only other colour pixels will be spliced).
176
- # @option options [Gosu::Color, Array<Float>, Symbol] :chroma_key_not Colour to copy (other colours won't be spliced).
177
- # @option options [Array<Float>] :crop ([0, 0, source.width - 1, source.height - 1]) Area of the source image to splice.
178
- # @return [Gosu::Image]
179
- def splice(x, y, source, options = {})
180
- end
181
- alias_method :composite, :splice
182
-
183
- # Generate binary data from the image.
184
- #
185
- # @note This method is usually overridden by the default Gosu::Image#to_blob.
186
- # @note This method causes a segmentation fault in Windows.
187
- # @return [String] Raw binary data (blob) in RGBA byte order.
188
- def to_blob
189
- end
190
- end
1
+ # -*- coding: iso-8859-1 -*-
2
+ # This code is never run; it is just here so we can document the C functions.
3
+
4
+
5
+ module TexPlay
6
+ # Draw a bezier curve.
7
+ #
8
+ # @param (see #polyline)
9
+ # @option (see #polyline)
10
+ # @return [Gosu::Image]
11
+ def bezier(points, options = {})
12
+ end
13
+
14
+ # Draw a circle.
15
+ #
16
+ # @note :thickness not implemented for circle.
17
+ #
18
+ # @param [Number] center_x Horizontal center.
19
+ # @param [Number] center_y Vertical center.
20
+ # @param [Number] radius Radius.
21
+ # @option (see #set_pixel)
22
+ # @option options [Boolean] :fill (false) Whether to fill in the shape.
23
+ # @option options [Boolean] :filled (false) Synonym for +:fill+
24
+ # @return [Gosu::Image]
25
+ def circle(center_x, center_y, radius, options = {})
26
+ end
27
+
28
+ # Make a copy of the image.
29
+ #
30
+ # @return [Gosu::Image] Deep copy of the image.
31
+ def clone()
32
+ end
33
+
34
+ # (see #clone)
35
+ def dup()
36
+ end
37
+
38
+ # Iterate through every pixel of the image, allowing modification of each pixels.
39
+ #
40
+ # @yield [color, x, y] Colour and position (arity == 3).
41
+ # @yield [color] Colour only (arity == 1).
42
+ # @yieldparam [Array<Float>] color RGBA colour array. This can be modified to affect the image directly.
43
+ # @yieldparam [Integer] x X position of the pixel.
44
+ # @yieldparam [Integer] y Y position of the pixel.
45
+ def each(&block)
46
+ end
47
+
48
+ # Perform a Flood Fill at a given position.
49
+ #
50
+ # @param [Number] x
51
+ # @param [Number] y
52
+ # @option options [Gosu::Color, Array<Float>, Symbol] :color (:white) Colour to apply to the drawing action.
53
+ # @option options [Proc, Hash] :color_control Effect to apply to the drawing action.
54
+ # @return [Gosu::Image]
55
+ def fill(x, y, options = {})
56
+ end
57
+
58
+ # Force synchronisation of the image (send from RAM to VRAM).
59
+ #
60
+ # @param [Array<Number>] rectangle Area to synchronise.
61
+ # @return [Gosu::Image]
62
+ def force_sync(rectangle = [0, 0, width, height])
63
+ end
64
+
65
+ # Get the colour of an individual pixel.
66
+ #
67
+ # @param [Number] x Horizontal position.
68
+ # @param [Number] y Vertical position.
69
+ # @return [Array<Float>] 4-element, RGBA colour array.
70
+ def get_pixel(x, y)
71
+ end
72
+
73
+ # @param [Number] x1 X position of start of line.
74
+ # @param [Number] y1 Y position of start of line.
75
+ # @param [Number] x2 X position of end of line.
76
+ # @param [Number] y2 Y position of end of line.
77
+ # @option (see #set_pixel)
78
+ # @option options [Number] :thickness (1) Thickness of the line.
79
+ # @option options [Hash] :trace Trace
80
+ # @return [Gosu::Image]
81
+ def line(x1, y1, x2, y2, options = {})
82
+ end
83
+
84
+ # Draw an n-sided polygon.
85
+ #
86
+ # @param (see #circle)
87
+ # @param [Integer] sides Number of sides for the polygon.
88
+ # @option (see #circle)
89
+ # @return [Gosu::Image]
90
+ def ngon(center_x, center_y, radius, sides, options = {})
91
+ end
92
+
93
+ # Offset all future drawing actions.
94
+ #
95
+ # The offset is non-stacking.
96
+ #
97
+ # Can also use +offset(:default)+ to reset offset to (0, 0).
98
+ #
99
+ # @param [Number] x
100
+ # @param [Number] y
101
+ # @return [Gosu::Image]
102
+ def offset(x, y)
103
+ end
104
+
105
+ # Perform drawing operations in the context of the image using _lazy_ syncing.
106
+ #
107
+ # A peculiarity of paint blocks is how they sync the drawing actions (syncing will be discussed in greater depth
108
+ # later on). The drawing actions in a Paint Block are not sync�d until the very end of the Paint Block and are then
109
+ # sync'd to video memory all in one go (This style of syncing is called _lazy_ syncing in TexPlay)
110
+ #
111
+ # @example Drawing to the image within a paint block
112
+ # image1.paint do
113
+ # circle 10, 10, 20, :color => :green
114
+ # bezier [0, 0, 10, 10, 50, 0], :closed => true
115
+ # end
116
+ #
117
+ # @option options [Symbol] :sync_mode (:lazy_sync) One of +:lazy_sync+, +:no_sync+ or +:eager_sync+
118
+ # @yield Block evaluated as the image.
119
+ # @return [Gosu::Image]
120
+ def paint(options = {}, &block)
121
+ end
122
+
123
+ # Draw a series of connected lines.
124
+ #
125
+ # @param [Array<Number, TPPoint>] points Series of points (either [x1, y1, x2, y2, ...] or [point1, point2]).
126
+ # @option (see #rect)
127
+ # @option options [Boolean] :closed Whether the last point is linked to the first.
128
+ # @return [Gosu::Image]
129
+ def polyline(points, options = {})
130
+ end
131
+
132
+ # Draw a rectangle.
133
+ #
134
+ # @param [Number] x1 Top of the rectangle.
135
+ # @param [Number] y1 Left of the rectangle.
136
+ # @param [Number] x2 Right of the rectangle.
137
+ # @param [Number] y2 Bottom of the rectangle.
138
+ # @option (see #circle)
139
+ # @option options [Number] :thickness (1) Thickness of the line.
140
+ # @return [Gosu::Image]
141
+ def rect(x1, y1, x2, y2, options = {})
142
+ end
143
+ alias_method :box, :rect
144
+
145
+ # Set the colour of an individual pixel.
146
+ #
147
+ # @param [Number] x
148
+ # @param [Number] y
149
+ # @option (see #fill)
150
+ # @option options [Boolean] :alpha_blend (false) Alpha-blend instead of overwrite.
151
+ # @option options [Gosu::Image] :texture Texture to use instead of a flat colour.
152
+ # @option options [Symbol] :mode (:copy) Drawing mode to use.
153
+ # @return [Gosu::Image]
154
+ def set_pixel(x, y, options = {})
155
+ end
156
+ alias_method :pixel, :set_pixel
157
+
158
+ # Copy an image into another image.
159
+ #
160
+ # @param [Number] x Horizontal position to splice at.
161
+ # @param [Number] y Vertical position to splice at.
162
+ # @param [Gosu::Image] source Image to copy from.
163
+ # @option options [Gosu::Color, Array<Float>, Symbol] :chroma_key Colour to treat as transparent (only other colour pixels will be spliced).
164
+ # @option options [Gosu::Color, Array<Float>, Symbol] :chroma_key_not Colour to copy (other colours won't be spliced).
165
+ # @option options [Array<Float>] :crop ([0, 0, source.width - 1, source.height - 1]) Area of the source image to splice.
166
+ # @return [Gosu::Image]
167
+ def splice(x, y, source, options = {})
168
+ end
169
+ alias_method :composite, :splice
170
+
171
+ # Generate binary data from the image.
172
+ #
173
+ # @note This method is usually overridden by the default Gosu::Image#to_blob.
174
+ # @note This method causes a segmentation fault in Windows.
175
+ # @return [String] Raw binary data (blob) in RGBA byte order.
176
+ def to_blob
177
+ end
178
+ end
data/lib/texplay/live.rb CHANGED
@@ -1,84 +1,84 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require "#{direc}/../texplay"
4
- require 'pry'
5
-
6
- WIDTH = 640
7
- HEIGHT = 480
8
-
9
- class Gosu::Image
10
- attr_accessor :x, :y
11
-
12
- alias_method :orig_init, :initialize
13
- def initialize(*args)
14
- @x = WIDTH / 2
15
- @y = HEIGHT / 2
16
- orig_init(*args)
17
- end
18
- end
19
-
20
- class WinClass < Gosu::Window
21
-
22
- class View
23
- attr_accessor :zoom, :rotate
24
-
25
- def initialize
26
- @zoom = 1
27
- @rotate = 0
28
- end
29
-
30
- def reset
31
- @zoom = 1
32
- @rotate = 0
33
- end
34
- end
35
-
36
- attr_reader :images, :view
37
-
38
- def initialize
39
- super(WIDTH, HEIGHT, false)
40
- Gosu.enable_undocumented_retrofication
41
-
42
- @images = []
43
- @view = View.new
44
- @pry_instance = Pry.new :prompt => [Proc.new { "(live)> " }, Proc.new { "(live)* " }]
45
-
46
- @img = TexPlay.create_image(self, 200, 200)
47
- @img.rect 0, 0, @img.width - 1, @img.height - 1
48
-
49
- images << @img
50
- @binding = binding
51
- end
52
-
53
- def create_image(width, height, options={})
54
- TexPlay.create_image(self, width, height, options)
55
- end
56
-
57
- def load_image(file)
58
- Gosu::Image.new(self, file)
59
- end
60
-
61
- def show_image(image)
62
- images << image
63
- end
64
-
65
- def hide_image(image)
66
- images.delete(image)
67
- end
68
-
69
- def draw
70
- images.uniq!
71
- images.each do |v|
72
- v.draw_rot(v.x, v.y, 1, view.rotate, 0.5, 0.5, view.zoom, view.zoom)
73
- end
74
- end
75
-
76
- def update
77
- @pry_instance.rep(@binding)
78
- end
79
- end
80
-
81
- w = WinClass.new
82
-
83
- w.show
84
-
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require "#{direc}/../texplay"
4
+ require 'pry'
5
+
6
+ WIDTH = 640
7
+ HEIGHT = 480
8
+
9
+ class Gosu::Image
10
+ attr_accessor :x, :y
11
+
12
+ alias_method :orig_init, :initialize
13
+ def initialize(*args)
14
+ @x = WIDTH / 2
15
+ @y = HEIGHT / 2
16
+ orig_init(*args)
17
+ end
18
+ end
19
+
20
+ class WinClass < Gosu::Window
21
+
22
+ class View
23
+ attr_accessor :zoom, :rotate
24
+
25
+ def initialize
26
+ @zoom = 1
27
+ @rotate = 0
28
+ end
29
+
30
+ def reset
31
+ @zoom = 1
32
+ @rotate = 0
33
+ end
34
+ end
35
+
36
+ attr_reader :images, :view
37
+
38
+ def initialize
39
+ super(WIDTH, HEIGHT, false)
40
+ Gosu.enable_undocumented_retrofication
41
+
42
+ @images = []
43
+ @view = View.new
44
+ @pry_instance = Pry.new :prompt => [Proc.new { "(live)> " }, Proc.new { "(live)* " }]
45
+
46
+ @img = TexPlay.create_image(self, 200, 200)
47
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
48
+
49
+ images << @img
50
+ @binding = binding
51
+ end
52
+
53
+ def create_image(width, height, options={})
54
+ TexPlay.create_image(self, width, height, options)
55
+ end
56
+
57
+ def load_image(file)
58
+ Gosu::Image.new(self, file)
59
+ end
60
+
61
+ def show_image(image)
62
+ images << image
63
+ end
64
+
65
+ def hide_image(image)
66
+ images.delete(image)
67
+ end
68
+
69
+ def draw
70
+ images.uniq!
71
+ images.each do |v|
72
+ v.draw_rot(v.x, v.y, 1, view.rotate, 0.5, 0.5, view.zoom, view.zoom)
73
+ end
74
+ end
75
+
76
+ def update
77
+ @pry_instance.rep(@binding)
78
+ end
79
+ end
80
+
81
+ w = WinClass.new
82
+
83
+ w.show
84
+