gist: 2597 Download_button fork
public
Public Clone URL: git://gist.github.com/2597.git
ball-tween.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
class Shape
  def tween opts, &blk
    a = parent.animate(opts[:speed] || 20) do
 
      # figure out a coordinate halfway between here and there
      n_left, n_top = opts[:left], opts[:top]
      n_left = self.left + ((n_left - self.left) / 2) if self.left != n_left
      n_top = self.top + ((n_top - self.top) / 2) if self.top != n_top
 
      # if we're there, get rid of the animation
      if self.left == n_left and self.top == n_top
        self.move(opts[:left], opts[:top])
        a.remove
        blk.call if blk
      end
 
      self.move(n_left, n_top)
    end
  end
end
 
moves = [[120, 120], [40, 80], [210, 20], [20, 20]]
i = 0
Shoes.app do
  c = oval :top => 20, :left => 20, :radius => 10
  c.click do
    left, top = moves[i % 4]
    c.tween :left => left, :top => top do
      i += 1
    end
  end
end

Owner

why

Revisions