texplay 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.markdown +35 -0
- data/README1st +1 -1
- data/Rakefile +6 -6
- data/examples/example_alpha_blend.rb +1 -1
- data/examples/example_bezier.rb +4 -13
- data/examples/example_color_control.rb +3 -2
- data/examples/example_color_transform.rb +3 -3
- data/examples/example_dup.rb +1 -1
- data/examples/example_each.rb +1 -1
- data/examples/example_effect.rb +1 -1
- data/examples/example_fill.rb +4 -9
- data/examples/example_fill_old.rb +1 -1
- data/examples/example_fluent.rb +1 -1
- data/examples/example_gen_eval.rb +1 -1
- data/examples/example_hash_arguments.rb +1 -1
- data/examples/example_melt.rb +1 -1
- data/examples/example_polyline.rb +1 -1
- data/examples/example_simple.rb +4 -1
- data/examples/example_splice.rb +9 -13
- data/examples/example_sync.rb +1 -1
- data/examples/example_turtle.rb +2 -2
- data/lib/texplay-contrib.rb +8 -8
- data/lib/texplay.rb +9 -9
- data/src/actions.c +80 -55
- data/src/bindings.c +2 -2
- data/src/texplay.c +1 -1
- data/src/utils.c +6 -5
- metadata +3 -9
- data/README +0 -21
- data/examples/basic.rb +0 -48
- data/examples/basic2.rb +0 -37
- data/examples/benchmark.rb +0 -299
- data/examples/specs.rb +0 -240
- data/examples/test.rb +0 -70
- data/examples/test2.rb +0 -72
data/examples/benchmark.rb
DELETED
@@ -1,299 +0,0 @@
|
|
1
|
-
# TexPlay test program
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rubygems'
|
5
|
-
rescue LoadError
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'common'
|
10
|
-
require 'gosu'
|
11
|
-
require 'texplay'
|
12
|
-
require 'benchmark'
|
13
|
-
|
14
|
-
class MyWindow < Gosu::Window
|
15
|
-
|
16
|
-
# set to true for visible output
|
17
|
-
# note, benchmarks will not happen until
|
18
|
-
# viewing window is closed
|
19
|
-
SHOW = false
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
super(1024, 768, false, 20)
|
23
|
-
@img = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
24
|
-
@img2 = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
25
|
-
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
26
|
-
@empty1 = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
27
|
-
@empty2 = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
28
|
-
@empty3 = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
29
|
-
@width = @img.width
|
30
|
-
@height = @img.height
|
31
|
-
|
32
|
-
# default number of iterations
|
33
|
-
@repeat = 1000
|
34
|
-
|
35
|
-
if ARGV.first.to_i != 0 then
|
36
|
-
@repeat = ARGV.shift.to_i
|
37
|
-
end
|
38
|
-
|
39
|
-
if SHOW then
|
40
|
-
class << self
|
41
|
-
alias_method :draw, :_draw
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def bench_all
|
47
|
-
x1 = rand @width
|
48
|
-
y1 = rand @height
|
49
|
-
x2 = rand @width
|
50
|
-
y2 = rand @height
|
51
|
-
|
52
|
-
@img.paint {
|
53
|
-
color :random
|
54
|
-
circle x1, y1, 10
|
55
|
-
line x1, y1, x2, y2
|
56
|
-
rect x1, y1, x2 + 100, y2 + 100
|
57
|
-
pixel x1, y1
|
58
|
-
}
|
59
|
-
end
|
60
|
-
|
61
|
-
def bench_clear
|
62
|
-
@img.paint {
|
63
|
-
clear
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
def bench_circle
|
68
|
-
x = rand @width
|
69
|
-
y = rand @height
|
70
|
-
r = 50
|
71
|
-
|
72
|
-
@img.circle x, y, r
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def bench_pixel
|
77
|
-
@img.paint {
|
78
|
-
color :random
|
79
|
-
pixel (@img.width * rand), (@img.width * rand)
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
def bench_splice
|
84
|
-
@img.paint {
|
85
|
-
splice(@img2, (@img.width * rand), (@img.height * rand))
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
def bench_splice_same
|
91
|
-
@img.paint {
|
92
|
-
splice(@img, (@img.width * rand), (@img.height * rand))
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
def bench_special_pixel
|
97
|
-
@img.paint {
|
98
|
-
self[(@img.width * rand), (@img.height * rand)] = :random
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def bench_line
|
103
|
-
x1 = rand @width
|
104
|
-
y1 = rand @height
|
105
|
-
x2 = rand @width
|
106
|
-
y2 = rand @height
|
107
|
-
|
108
|
-
|
109
|
-
@img.line x1, y1, x2, y2
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
def bench_pline
|
114
|
-
x1 = rand @width
|
115
|
-
y1 = rand @height
|
116
|
-
x2 = rand @width
|
117
|
-
y2 = rand @height
|
118
|
-
|
119
|
-
|
120
|
-
@img.paint {
|
121
|
-
line x1, y1, x2, y2
|
122
|
-
}
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
def bench_box
|
127
|
-
x1 = rand @width
|
128
|
-
y1 = rand @height
|
129
|
-
x2 = rand @width
|
130
|
-
y2 = rand @height
|
131
|
-
|
132
|
-
@img.paint {
|
133
|
-
rect rand(@width),rand(@width),rand(@width),rand(@width)
|
134
|
-
}
|
135
|
-
end
|
136
|
-
|
137
|
-
def bench_anti_each
|
138
|
-
0.upto(@img.width - 1) { |x|
|
139
|
-
0.upto(@img.height - 1) { |y|
|
140
|
-
clr = @img.get_pixel(x, y)
|
141
|
-
|
142
|
-
clr[0] += 1
|
143
|
-
|
144
|
-
@img.color clr
|
145
|
-
@img.pixel(x, y)
|
146
|
-
}
|
147
|
-
}
|
148
|
-
end
|
149
|
-
|
150
|
-
def bench_each
|
151
|
-
@img.each { |v| v[0] = 1}
|
152
|
-
end
|
153
|
-
|
154
|
-
def bench_each2
|
155
|
-
@img.each2 { |v| v[0] = 1}
|
156
|
-
end
|
157
|
-
|
158
|
-
def bench_image_new
|
159
|
-
Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
160
|
-
end
|
161
|
-
|
162
|
-
def bench_create_blank
|
163
|
-
truck = TexPlay::create_blank_image(self, @img.width, @img.height)
|
164
|
-
truck.splice(@img, 0, 0)
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
def bench_dup
|
169
|
-
@img.dup
|
170
|
-
end
|
171
|
-
|
172
|
-
def bench_clone
|
173
|
-
@img.clone
|
174
|
-
end
|
175
|
-
|
176
|
-
def bench_composite
|
177
|
-
@img.splice @img2, 0, 0
|
178
|
-
end
|
179
|
-
|
180
|
-
def bench_rect
|
181
|
-
@img.rect 0, 0, 1024, 1024, :fill => true
|
182
|
-
end
|
183
|
-
|
184
|
-
def bench_gen_eval
|
185
|
-
@img.paint {
|
186
|
-
0.upto(1000) {
|
187
|
-
circle 100,100, 10
|
188
|
-
}
|
189
|
-
}
|
190
|
-
end
|
191
|
-
|
192
|
-
def bench_eager_sync
|
193
|
-
@img.paint(:lazy_sync => false) {
|
194
|
-
# 1.upto(1000) {
|
195
|
-
# color :blue
|
196
|
-
### circle (10), (10), 10
|
197
|
-
clear
|
198
|
-
#circle (@img.width * rand), (@img.height * rand), 10
|
199
|
-
# }
|
200
|
-
}
|
201
|
-
end
|
202
|
-
|
203
|
-
def bench_lazy_sync
|
204
|
-
@img.paint(:lazy_sync => true) {
|
205
|
-
# 1.upto(1000) {
|
206
|
-
# color :blue
|
207
|
-
# circle (10), (10), 10
|
208
|
-
clear
|
209
|
-
#circle (@img.width * rand), (@img.height * rand), 10
|
210
|
-
# }
|
211
|
-
|
212
|
-
}
|
213
|
-
end
|
214
|
-
|
215
|
-
|
216
|
-
def bench_yield
|
217
|
-
@img.paint { |c|
|
218
|
-
0.upto(1000) {
|
219
|
-
c.circle 100,100, 10
|
220
|
-
}
|
221
|
-
}
|
222
|
-
end
|
223
|
-
|
224
|
-
def bench_instance_eval
|
225
|
-
@img.instance_eval {
|
226
|
-
0.upto(1000) {
|
227
|
-
circle 100,100, 10
|
228
|
-
}
|
229
|
-
}
|
230
|
-
end
|
231
|
-
|
232
|
-
def bench_glow_fill
|
233
|
-
@empty2.fill 100,100
|
234
|
-
end
|
235
|
-
|
236
|
-
def bench_scan_fill_style
|
237
|
-
@empty2.fill 100,100, :scan => true, :style => true, :color => :random
|
238
|
-
end
|
239
|
-
|
240
|
-
def bench_scan_fill
|
241
|
-
@empty3.fill 100,100, :scan => true, :color => :random
|
242
|
-
end
|
243
|
-
|
244
|
-
def bench_iter_fill
|
245
|
-
@empty3.fill 100,100, :iter => true
|
246
|
-
end
|
247
|
-
|
248
|
-
def bench_polyline_thick
|
249
|
-
@empty2.polyline [100, 200, 0, 0, 150, 500, 500, 0], :closed => true, :texture => @tp, :thickness => 2,
|
250
|
-
:alpha_blend => true, :sync_mode => :no_sync
|
251
|
-
end
|
252
|
-
|
253
|
-
def bench_polyline
|
254
|
-
ps = []
|
255
|
-
13.times {
|
256
|
-
p = [@empty2.width * rand, @empty2.height * rand]
|
257
|
-
ps += p
|
258
|
-
}
|
259
|
-
# ps = [110, 110, 210, 210]
|
260
|
-
@empty2.polyline ps
|
261
|
-
end
|
262
|
-
|
263
|
-
def bench_bezier
|
264
|
-
ps = []
|
265
|
-
13.times {
|
266
|
-
p = [@empty2.width * rand, @empty2.height * rand]
|
267
|
-
ps += p
|
268
|
-
}
|
269
|
-
@empty2.bezier ps
|
270
|
-
end
|
271
|
-
|
272
|
-
def _draw
|
273
|
-
@img.draw(200, 200, 0)
|
274
|
-
end
|
275
|
-
|
276
|
-
def do_benchmarks
|
277
|
-
puts "performing #{@repeat} iterations..."
|
278
|
-
|
279
|
-
bench_meths = ARGV
|
280
|
-
|
281
|
-
if ARGV.empty? then
|
282
|
-
bench_meths = self.methods.select { |x| x =~ /bench/ }.map { |x| x.to_s.sub("bench_", "") }
|
283
|
-
end
|
284
|
-
|
285
|
-
Benchmark.bmbm do |v|
|
286
|
-
bench_meths.each { |meth|
|
287
|
-
v.report(meth) { @repeat.times { self.send("bench_#{meth}") } }
|
288
|
-
}
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
w = MyWindow.new
|
294
|
-
|
295
|
-
if MyWindow::SHOW
|
296
|
-
w.show
|
297
|
-
end
|
298
|
-
|
299
|
-
w.do_benchmarks
|
data/examples/specs.rb
DELETED
@@ -1,240 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
|
-
rquire 'common'
|
5
|
-
require 'gosu'
|
6
|
-
require 'texplay'
|
7
|
-
|
8
|
-
class MyWindow < Gosu::Window
|
9
|
-
def initialize
|
10
|
-
super(1024, 769, false, 20)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
W = MyWindow.new
|
15
|
-
|
16
|
-
class MyTest < Test::Unit::TestCase
|
17
|
-
|
18
|
-
context "TexPlay Bug Eradicator" do
|
19
|
-
setup do
|
20
|
-
@img = Gosu::Image.new(W, "#{Common::MEDIA}/empty2.png")
|
21
|
-
@gosu = Gosu::Image.new(W, "#{Common::MEDIA}/gosu.png")
|
22
|
-
@points = []
|
23
|
-
end
|
24
|
-
|
25
|
-
should "not have gaps in polyline from 2nd to 3rd point" do
|
26
|
-
@img.polyline 0, 0, 40, 40, 38, 1024
|
27
|
-
end
|
28
|
-
|
29
|
-
should "not freeze when using floodfill and a color_control block" do
|
30
|
-
# rectangle to fill
|
31
|
-
@img.rect 40, 40, 100, 100
|
32
|
-
|
33
|
-
# works fine WITHOUT color_control block, wtf?
|
34
|
-
@img.fill 90, 90, :color_control => proc { |c, x, y| :red }
|
35
|
-
end
|
36
|
-
|
37
|
-
# this problem is due to inability to calculate factorials > 15
|
38
|
-
should "beziers should not CLUSTER around top left hand corner when num random points > 15" do
|
39
|
-
15.times {
|
40
|
-
p = [(@img.width * rand()), (@img.height * rand())]
|
41
|
-
@points += p
|
42
|
-
}
|
43
|
-
@img.paint {
|
44
|
-
bezier @points
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
# fixed
|
49
|
-
should "make composite actions imitate primitives, i.e random color does not trickle to sub actions" do
|
50
|
-
# comprised of filled circles
|
51
|
-
@img.line 300, 300, 500, 500, :color => :random, :thickness => 5
|
52
|
-
|
53
|
-
# comprised of lines
|
54
|
-
@img.circle 40, 300, 10, :color => :random, :fill => true
|
55
|
-
end
|
56
|
-
|
57
|
-
should "this crashes the stack after a little while" do
|
58
|
-
l = ->() { 2 * @img.width * rand - @img.width / 2 }
|
59
|
-
|
60
|
-
points = []
|
61
|
-
10.times {
|
62
|
-
points += [l.(), l.()]
|
63
|
-
}
|
64
|
-
|
65
|
-
@img.bezier points, :closed => true
|
66
|
-
|
67
|
-
@img.fill l.(), l.(), :color => :random#, :scan => true
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
should "fill crashes when using alpha_blend => true" do
|
72
|
-
@img.fill 250, 487, :texture => @tp, :scan => true, :alpha_blend => true
|
73
|
-
end
|
74
|
-
|
75
|
-
# FIXED ! simply did not initialize TexPlay::TPPoint, duh!
|
76
|
-
should "not ERROR about finding ivar @turtle_pos, SUPPOSED to be eval'd in context of @img" do
|
77
|
-
@img.paint {
|
78
|
-
forward(50, true, :color => :red)
|
79
|
-
turn(@length)
|
80
|
-
}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "effects" do
|
85
|
-
setup do
|
86
|
-
@length = 1
|
87
|
-
@img = Gosu::Image.new(W, "empty2.png")
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
should "this is just a cool effect using turtle and random fill" do
|
92
|
-
@img.paint {
|
93
|
-
forward(@length, true, :color => :red)
|
94
|
-
turn(170)
|
95
|
-
@length += 5
|
96
|
-
}
|
97
|
-
@img.fill (@img.width * rand), (@img.height * rand), :color => :random
|
98
|
-
end
|
99
|
-
|
100
|
-
should "another cool effect using turtle" do
|
101
|
-
@length = 0
|
102
|
-
@img.paint {
|
103
|
-
forward(20, true, :color => red)
|
104
|
-
turn(@length)
|
105
|
-
@length += 10
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
should "draw a circle with a rough edge utilizing color_control block and :none (no color)" do
|
110
|
-
@img.circle 200,200, 100,
|
111
|
-
:color_control => proc { |c,x,y|
|
112
|
-
@img.pixel(x + (rand(4) - 2), y + (rand(4) - 2))
|
113
|
-
:none # this ensures that the 'actual' circle isn't drawn, instead its coordinates are
|
114
|
-
# simply utilized to draw a ragged edge of another circle (using @img.pixel)
|
115
|
-
}
|
116
|
-
end
|
117
|
-
|
118
|
-
context "examples" do
|
119
|
-
setup do
|
120
|
-
@img = Gosu::Image.new(W, "empty2.png")
|
121
|
-
@tp = Gosu::Image.new(W, "texplay.png")
|
122
|
-
end
|
123
|
-
|
124
|
-
should "draw closed polyline" do
|
125
|
-
@img.polyline 0,0 , 40, 40, 400, 300, 100, 20, :closed => true, :thickness => 1
|
126
|
-
end
|
127
|
-
|
128
|
-
should "texture fill an area using :texture hash arg" do
|
129
|
-
@img.polyline 30, 30, 100, 100, 200, 76, 300, 9, 50, 200, :color => :random, :closed => true
|
130
|
-
@img.fill 42, 70, :texture => @tp
|
131
|
-
end
|
132
|
-
|
133
|
-
should "texture fill an area using color_control" do
|
134
|
-
@img.polyline 30, 30, 100, 100, 200, 76, 300, 9, 50, 200, :color => :random, :closed => true
|
135
|
-
@img.fill 42, 70, :color_control => proc { |c, x, y|
|
136
|
-
@tp.get_pixel(x % @tp.width, y % @tp.height)
|
137
|
-
}
|
138
|
-
end
|
139
|
-
|
140
|
-
should "average the color between the texture image and the background image" do
|
141
|
-
@img.rect 10, 10, 100, 100, :filled => true, :texture => @tp,
|
142
|
-
:color_control => proc { |c1, c2|
|
143
|
-
c1[0] = (c1[0] + c2[0] / 2 )
|
144
|
-
c1[1] = (c1[1] + c2[1] / 2 )
|
145
|
-
c1[2] = (c1[2] + c2[2] / 2 )
|
146
|
-
c1[3] = 1
|
147
|
-
c1
|
148
|
-
}
|
149
|
-
end
|
150
|
-
|
151
|
-
should "force a texture to alpha blend even when it has a full opacity" do
|
152
|
-
@img.circle 100, 100, 50, :alpha_blend => true, :fill => true, :texture => @gosu,
|
153
|
-
:color_control => proc { |c, c1|
|
154
|
-
c1[3] = 0.1
|
155
|
-
c1
|
156
|
-
}
|
157
|
-
end
|
158
|
-
|
159
|
-
should "draw lines with thickness, using color_control block" do
|
160
|
-
x1 = @img.width * rand
|
161
|
-
y1 = @img.height * rand
|
162
|
-
x2 = @img.width * rand
|
163
|
-
y2 = @img.height * rand
|
164
|
-
|
165
|
-
# thickness of lines
|
166
|
-
t = 30
|
167
|
-
|
168
|
-
@img.paint {
|
169
|
-
line x1, y1, x2, y2, :color_control => proc { |c, x, y|
|
170
|
-
|
171
|
-
# vectors
|
172
|
-
vx = x2 - x1
|
173
|
-
vy = y2 - y1
|
174
|
-
|
175
|
-
# unit vectors
|
176
|
-
uvx = vx / Math::hypot(vx, vy)
|
177
|
-
uvy = vy / Math::hypot(vx, vy)
|
178
|
-
|
179
|
-
# draw lines at perpendicular
|
180
|
-
line x, y, x - (uvy*t), y + (uvx*t), :color => :red
|
181
|
-
|
182
|
-
# original line is white
|
183
|
-
:white
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
should "do an alternative way to thick draw lines" do
|
191
|
-
x1 = @img.width * rand
|
192
|
-
y1 = @img.height * rand
|
193
|
-
x2 = @img.width * rand
|
194
|
-
y2 = @img.height * rand
|
195
|
-
|
196
|
-
t = 30
|
197
|
-
|
198
|
-
vx = x2 - x1
|
199
|
-
vy = y2 - y1
|
200
|
-
|
201
|
-
uvx = vx / Math::hypot(vx, vy)
|
202
|
-
uvy = vy / Math::hypot(vx, vy)
|
203
|
-
|
204
|
-
@img.paint {
|
205
|
-
line x1, y1, x2, y2
|
206
|
-
t.times { |i|
|
207
|
-
line x1 - (uvy * i), y1 + (uvx * i), x2 - (uvy * i), y2 + (uvx*t), :color => :random
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
context "bezier context" do
|
217
|
-
setup do
|
218
|
-
@points = []
|
219
|
-
@p = TexPlay::TPPoint.new
|
220
|
-
@p.x, @p.y = 0, 0
|
221
|
-
@points << @p
|
222
|
-
(0..@img.width).step(80) do |x|
|
223
|
-
@p = TexPlay::TPPoint.new
|
224
|
-
@p.x = x
|
225
|
-
@p.y = rand(@img.height) * 2 - @img.height / 2
|
226
|
-
@points << @p
|
227
|
-
end
|
228
|
-
@p = TexPlay::TPPoint.new
|
229
|
-
@p.x, @p.y = @img.width, 0
|
230
|
-
@points << @p
|
231
|
-
end
|
232
|
-
|
233
|
-
should "draw a bezier curve that spans the image width" do
|
234
|
-
@img.bezier(*@points)
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
data/examples/test.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'gosu'
|
3
|
-
require 'texplay'
|
4
|
-
|
5
|
-
class MyWindow < Gosu::Window
|
6
|
-
def initialize
|
7
|
-
super(1024, 768, false, 20)
|
8
|
-
|
9
|
-
# image for texture filling
|
10
|
-
@gosu = Gosu::Image.new(self,"#{Common::MEDIA}/gosu.png")
|
11
|
-
|
12
|
-
# images for testing
|
13
|
-
@unchanged = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
14
|
-
@simple = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
15
|
-
@polyline = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
16
|
-
@bezier = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
17
|
-
@flood_fill = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
18
|
-
|
19
|
-
# height and width
|
20
|
-
@width = @simple.width
|
21
|
-
@height = @simple.height
|
22
|
-
|
23
|
-
# initializations
|
24
|
-
setup_simple
|
25
|
-
setup_polyline
|
26
|
-
setup_bezier
|
27
|
-
setup_flood_fill
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def setup_simple
|
32
|
-
@simple.line 0, 0, 1024, 1024
|
33
|
-
@simple.rect 0,0, @width - 1, @height - 1
|
34
|
-
@simple.circle @simple.width/2, @simple.height/2, 30
|
35
|
-
end
|
36
|
-
|
37
|
-
def setup_polyline
|
38
|
-
@polyline.polyline [0, 0, @width / 2, @height - 1, @width - 1, 0]
|
39
|
-
end
|
40
|
-
|
41
|
-
def setup_bezier
|
42
|
-
points = []
|
43
|
-
10.times {
|
44
|
-
point = []
|
45
|
-
point[0] = @width * rand
|
46
|
-
point[1] = @height * rand
|
47
|
-
|
48
|
-
points += point
|
49
|
-
}
|
50
|
-
@bezier.bezier points
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup_flood_fill
|
54
|
-
@flood_fill.fill 100, 96, :color => :random, :scan => true
|
55
|
-
end
|
56
|
-
|
57
|
-
def draw
|
58
|
-
|
59
|
-
@simple.draw(20, 10, 1)
|
60
|
-
@polyline.draw(20, 210, 1)
|
61
|
-
@bezier.draw(20, 410, 1)
|
62
|
-
@flood_fill.draw(400, 10, 1)
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
w = MyWindow.new
|
68
|
-
w.show
|
69
|
-
|
70
|
-
|
data/examples/test2.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'gosu'
|
3
|
-
require 'texplay'
|
4
|
-
|
5
|
-
class MyWindow < Gosu::Window
|
6
|
-
def initialize
|
7
|
-
super(1024, 768, false, 20)
|
8
|
-
|
9
|
-
# image for texture filling
|
10
|
-
@gosu = Gosu::Image.new(self,"#{Common::MEDIA}/gosu.png")
|
11
|
-
|
12
|
-
# images for testing
|
13
|
-
@unchanged = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
14
|
-
@simple = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
15
|
-
@polyline = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
16
|
-
@bezier = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
17
|
-
@flood_fill = Gosu::Image.new(self,"#{Common::MEDIA}/texplay.png")
|
18
|
-
|
19
|
-
# height and width
|
20
|
-
@width = @simple.width
|
21
|
-
@height = @simple.height
|
22
|
-
|
23
|
-
# initializations
|
24
|
-
setup_simple
|
25
|
-
setup_polyline
|
26
|
-
setup_bezier
|
27
|
-
setup_flood_fill
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def setup_simple
|
32
|
-
@simple.line 0, 0, 1024, 1024
|
33
|
-
@simple.rect 0,0, @width - 1, @height - 1
|
34
|
-
@simple.circle @simple.width/2, @simple.height/2, 30
|
35
|
-
end
|
36
|
-
|
37
|
-
def setup_polyline
|
38
|
-
@polyline.polyline [0, 0, @width / 2, @height - 1, @width - 1, 0]
|
39
|
-
end
|
40
|
-
|
41
|
-
def setup_bezier
|
42
|
-
points = []
|
43
|
-
10.times {
|
44
|
-
point = []
|
45
|
-
point[0] = @width * rand
|
46
|
-
point[1] = @height * rand
|
47
|
-
|
48
|
-
points += point
|
49
|
-
}
|
50
|
-
@bezier.bezier points
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup_flood_fill
|
54
|
-
@flood_fill.fill 100, 96, :color => :random
|
55
|
-
end
|
56
|
-
|
57
|
-
def draw
|
58
|
-
|
59
|
-
@simple.draw(20, 10, 1)
|
60
|
-
@polyline.draw(20, 210, 1)
|
61
|
-
@bezier.draw(20, 410, 1)
|
62
|
-
@flood_fill.draw(400, 10, 1)
|
63
|
-
|
64
|
-
@polyline.paint
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
w = MyWindow.new
|
70
|
-
w.show
|
71
|
-
|
72
|
-
|