-
Notifications
You must be signed in to change notification settings - Fork 19
/
curve-control-point.rb
51 lines (45 loc) · 1.36 KB
/
curve-control-point.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# https://github.com/casparjones/First-Ruby-Steps/blob/master/shoes-samples/simple-curve.rb
# http://www.cairographics.org/samples/curve_to/
# curve_to with visible control points.
# The ovals represent the control points.
Shoes.app(title: "Expert curve_to control points", width: 500, height: 400) do
xy = [
[self.width / 8, self.height / 2],
[self.width / 8 * 3, self.height / 4 * 3],
[self.width / 8 * 4, self.height / 4],
[self.width / 8 * 7, self.height / 2]
]
para "click and drag control points..."
fill green(0.2)
move_to *xy[0]
@controller = nil
xy.each { |n|
(@controllers ||= []) << oval(:left => n[0], :top => n[1], :radius => 10, :center => true)
}
@controllers.each { |n|
n.click do |btn, left, top|
n.style :fill => red
@controller = n
end
n.release do |btn, left, top|
n.style :fill => green(0.2)
@controller = nil
end
}
motion do |left, top|
unless @controller.nil?
xy[@controllers.index(@controller)] = left, top
@controller.left, @controller.top = left, top
end
end
@stack = stack :top => 0, :left => 0
animate(10) do
@stack.clear do
fill red(0.2)
shape do
move_to *xy[0]
curve_to *xy[1], *xy[2], *xy[3]
end
end
end
end