-
Notifications
You must be signed in to change notification settings - Fork 19
/
path-animation.rb
46 lines (40 loc) · 1.23 KB
/
path-animation.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
Shoes.app(title: "Drag the dot to make a path. Redrag to extend.") do
@path = [[self.width / 2, self.height / 2, RADIUS = 20]]
@controller = nil
click do |btn, left, top|
px, py, pr = @path.last
if left.between?(px - pr, px + pr) and top.between?(py - pr, py + pr)
@controller = true
end
end
release do |btn, left, top|
@controller = nil
end
motion do |left, top|
@path << [left, top, RADIUS] unless @controller.nil?
end
button("reset") do
@index = 0
@path = [@path.first]
@controller = nil
end
@stack = stack :top => 0, :left => 0
@index = 0
animate(24) do
@stack.clear do
fill red(0.05)
stroke red(0.05)
ovals = @path.collect { |x, y, r| oval x, y, r, :center => true }
ovals.first.style :fill => fuchsia, :stroke => fuchsia
ovals.last.style :fill => blue, :stroke => blue
if @controller.nil? and @path.size > 1
fill green
stroke green
rotate -5
x, y, r = @path[@index]
rect x, y, r * 4, r * 4, r / 2, :center => true
@index = (@index < @path.size - 1) ? @index + 1 : 0
end
end
end
end