texplay 0.2.1-x86-mswin32-60
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.
- data/CHANGELOG +68 -0
- data/README +21 -0
- data/README1st +9 -0
- data/Rakefile +85 -0
- data/examples/basic.rb +48 -0
- data/examples/basic2.rb +37 -0
- data/examples/benchmark.rb +299 -0
- data/examples/common.rb +8 -0
- data/examples/example_alpha_blend.rb +31 -0
- data/examples/example_bezier.rb +51 -0
- data/examples/example_color_control.rb +68 -0
- data/examples/example_color_transform.rb +29 -0
- data/examples/example_dup.rb +52 -0
- data/examples/example_each.rb +42 -0
- data/examples/example_effect.rb +35 -0
- data/examples/example_fill.rb +49 -0
- data/examples/example_fill_old.rb +49 -0
- data/examples/example_fluent.rb +31 -0
- data/examples/example_gen_eval.rb +34 -0
- data/examples/example_hash_arguments.rb +47 -0
- data/examples/example_melt.rb +27 -0
- data/examples/example_polyline.rb +43 -0
- data/examples/example_simple.rb +35 -0
- data/examples/example_sync.rb +60 -0
- data/examples/example_turtle.rb +40 -0
- data/examples/media/empty2.png +0 -0
- data/examples/media/gosu.png +0 -0
- data/examples/media/maria.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/examples/media/sand1.png +0 -0
- data/examples/media/sunset.png +0 -0
- data/examples/media/texplay.png +0 -0
- data/examples/specs.rb +240 -0
- data/examples/test.rb +70 -0
- data/examples/test2.rb +72 -0
- data/lib/ctexplay.18.so +0 -0
- data/lib/ctexplay.19.so +0 -0
- data/lib/texplay-contrib.rb +77 -0
- data/lib/texplay.rb +134 -0
- data/src/Makefile +181 -0
- data/src/TAGS +286 -0
- data/src/actions.c +1306 -0
- data/src/actions.h +52 -0
- data/src/actions.obj +0 -0
- data/src/bindings.c +1081 -0
- data/src/bindings.h +45 -0
- data/src/bindings.obj +0 -0
- data/src/cache.c +132 -0
- data/src/cache.h +24 -0
- data/src/cache.obj +0 -0
- data/src/compat.h +23 -0
- data/src/ctexplay-i386-mswin32.def +2 -0
- data/src/ctexplay-i386-mswin32.exp +0 -0
- data/src/ctexplay-i386-mswin32.lib +0 -0
- data/src/ctexplay-i386-mswin32.pdb +0 -0
- data/src/ctexplay.so +0 -0
- data/src/extconf.rb +18 -0
- data/src/gen_eval.c +209 -0
- data/src/gen_eval.h +20 -0
- data/src/gen_eval.obj +0 -0
- data/src/mkmf.log +18 -0
- data/src/object2module.c +171 -0
- data/src/object2module.h +11 -0
- data/src/object2module.obj +0 -0
- data/src/texplay.c +136 -0
- data/src/texplay.h +107 -0
- data/src/texplay.obj +0 -0
- data/src/utils.c +959 -0
- data/src/utils.h +143 -0
- data/src/utils.obj +0 -0
- data/src/vc60.pdb +0 -0
- metadata +132 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 769, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
|
11
|
+
@width = @img.width
|
12
|
+
@height = @img.height
|
13
|
+
|
14
|
+
# turn alpha blending and filling on
|
15
|
+
@img.set_options :alpha_blend => true, :fill => true
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
|
20
|
+
# Gen_eval lets us use local instance vars within the block
|
21
|
+
# even though the block appears to be getting instance_eval'd
|
22
|
+
# for more information see gen_eval.c and object2module.c
|
23
|
+
@img.paint {
|
24
|
+
rect @width * rand, @height * rand, @width * rand, @height * rand,
|
25
|
+
:color => [rand, rand ,rand, rand]
|
26
|
+
}
|
27
|
+
|
28
|
+
@img.draw 100, 50,1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
w = W.new
|
33
|
+
w.show
|
34
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 769, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
11
|
+
|
12
|
+
|
13
|
+
# put a border on the image
|
14
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
15
|
+
|
16
|
+
# it can be annoying having to specify a bunch of :hash_arguments for every action
|
17
|
+
# here is how you specify common hash args that all actions will use (in the same image)
|
18
|
+
|
19
|
+
# all actions that respond to 'thickness' use a thickness of 8 pixels
|
20
|
+
# also set the color to random
|
21
|
+
@img.set_options :thickness => 8, :color => :rand
|
22
|
+
|
23
|
+
@img.rect 100, 100, 200, 200, :fill => false
|
24
|
+
|
25
|
+
# NOTE: for ngon, the parameters are as follows: x, y, radius, num_sides
|
26
|
+
@img.ngon 400, 400, 40, 3
|
27
|
+
|
28
|
+
# NOTE: the defaults can also be overidden:
|
29
|
+
@img.ngon 400, 200, 90, 6, :thickness => 1
|
30
|
+
|
31
|
+
# you can also delete the defaults
|
32
|
+
@img.delete_options
|
33
|
+
|
34
|
+
# this action will no longer have any default values
|
35
|
+
@img.ngon 200, 400, 90, 10
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw
|
39
|
+
@img.draw 100, 50,1
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
w = W.new
|
46
|
+
w.show
|
47
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
|
7
|
+
class W < Gosu::Window
|
8
|
+
def initialize
|
9
|
+
super(1024, 769, false, 20)
|
10
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
x = (@img.width - 100/2) * rand
|
15
|
+
y = (@img.height - 100/2) * rand
|
16
|
+
|
17
|
+
@img.splice @img, x, y + 1, :crop => [x, y, x + 100, y + 100]
|
18
|
+
|
19
|
+
@img.draw 100, 50,1
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
w = W.new
|
26
|
+
w.show
|
27
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 769, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
|
11
|
+
# put a border on the image
|
12
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
13
|
+
|
14
|
+
points = []
|
15
|
+
|
16
|
+
# NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
|
17
|
+
10.times {
|
18
|
+
p = TexPlay::TPPoint.new
|
19
|
+
p.x = @img.width * rand
|
20
|
+
p.y = @img.height * rand
|
21
|
+
|
22
|
+
points << p
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
# what if we want to turn a polyline into a polygon?
|
27
|
+
@img.polyline points, :closed => true, :color => :blue
|
28
|
+
@img.polyline points, :color => :red
|
29
|
+
end
|
30
|
+
|
31
|
+
def draw
|
32
|
+
|
33
|
+
# NOTE: (when viewing) the blue line is the extra line added to close the polygon,
|
34
|
+
# red lines are original polyline
|
35
|
+
@img.draw 100, 50,1
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
w = W.new
|
42
|
+
w.show
|
43
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
|
7
|
+
class W < Gosu::Window
|
8
|
+
def initialize
|
9
|
+
super(1024, 769, false, 20)
|
10
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
11
|
+
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
12
|
+
|
13
|
+
# put a border on the image
|
14
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
15
|
+
|
16
|
+
# perform some simple drawing actions
|
17
|
+
@img.line 0,0, @img.width - 1, @img.height - 1, :color => :yellow
|
18
|
+
@img.circle 400, 100, 40, :fill => true, :color => [rand, rand, rand, 1]
|
19
|
+
@img.rect 200, 300, 300, 400, :fill => true, :color => :red
|
20
|
+
|
21
|
+
# NOTE: chroma_key means NOT to splice in that color (pixels with that color are skipped)
|
22
|
+
# (chroma_key_not does the opposite, it skips pixels that do NOT have that color)
|
23
|
+
@img.splice @gosu, 210, 330, :chroma_key => :alpha
|
24
|
+
end
|
25
|
+
|
26
|
+
def draw
|
27
|
+
@img.draw 100, 50,1
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
w = W.new
|
34
|
+
w.show
|
35
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 769, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
|
11
|
+
# sets the 'global' color for all actions in this image
|
12
|
+
@img.color :red
|
13
|
+
|
14
|
+
# let's draw the circle without syncing it to gl
|
15
|
+
@img.circle 100, 100, 50, :fill => true, :sync_mode => :no_sync
|
16
|
+
|
17
|
+
# now let's sync half of it to gl
|
18
|
+
@img.force_sync [100, 50, 150, 150]
|
19
|
+
|
20
|
+
# let's draw some lazy shapes
|
21
|
+
@img.set_options :sync_mode => :lazy_sync
|
22
|
+
|
23
|
+
@img.ngon 200, 300, 40, 5, :color => :red
|
24
|
+
@img.ngon 280, 300, 40, 6, :color => :green
|
25
|
+
@img.ngon 360, 300, 40, 7, :color => :blue
|
26
|
+
|
27
|
+
# now let's sync the lazy shapes to gl
|
28
|
+
@img.paint
|
29
|
+
|
30
|
+
# NOTE: the lazy drawing (above) is identical to using the following paint block
|
31
|
+
# @img.paint {
|
32
|
+
# ngon 200, 300, 50, 5
|
33
|
+
# ...etc
|
34
|
+
# }
|
35
|
+
|
36
|
+
# end lazy drawing mode
|
37
|
+
@img.delete_options
|
38
|
+
|
39
|
+
# the default sync mode is eager_sync
|
40
|
+
# in this mode actions are drawn and sync'd immediately
|
41
|
+
# NOTE: TexPlay only syncs the part of the image that changed to gl
|
42
|
+
@img.ngon 440, 300, 40, 8, :color => :tyrian
|
43
|
+
|
44
|
+
# paint blocks can also accept a sync_mode parameter
|
45
|
+
# NOTE: the line below will not be visible until you
|
46
|
+
# explictly sync it to gl; probably using @img.force_sync
|
47
|
+
@img.paint(:sync_mode => :no_sync) {
|
48
|
+
line 0, 0, @img.width, @img.height
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def draw
|
53
|
+
|
54
|
+
@img.draw 100, 50,1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
w = W.new
|
59
|
+
w.show
|
60
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
|
6
|
+
class W < Gosu::Window
|
7
|
+
def initialize
|
8
|
+
super(1024, 769, false, 20)
|
9
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
10
|
+
|
11
|
+
# put a border on the image
|
12
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
13
|
+
|
14
|
+
@length = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# NOTE: turtle is currently written in Ruby so is very slow, look at texplay-contrib.rb for source code.
|
19
|
+
def draw
|
20
|
+
|
21
|
+
# NOTE: putting actions in paint block means they are only sync'd to gl at end of block.
|
22
|
+
# compare to calling an action directly (on an @img) where it is sync'd to gl immediately
|
23
|
+
|
24
|
+
@img.paint {
|
25
|
+
|
26
|
+
# a 2nd arg of 'true' means to show the turtle
|
27
|
+
forward(@length, true, :color => :red)
|
28
|
+
turn(89.5)
|
29
|
+
@length += 2
|
30
|
+
}
|
31
|
+
|
32
|
+
@img.draw 100, 50,1
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
w = W.new
|
39
|
+
w.show
|
40
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/examples/specs.rb
ADDED
@@ -0,0 +1,240 @@
|
|
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
|
+
|