1 require 'animation_field'
8 anim = animations.dup.compact
9 Animation.new("group (#{anim.size})") do |i|
17 def sequence(*animations)
18 anim = animations.dup.compact
19 return nil if anim.empty?
20 Animation.new("sequence (#{anim.size})") do |i|
28 def movement(item, src, dst, path_factory)
30 src = board.to_real(src)
31 dst = board.to_real(dst)
32 path = path_factory.new(src, dst)
34 SimpleAnimation.new "move to #{dst}", LENGTH, nil,
35 lambda {|i| item.pos = src + path[i] },
36 lambda { item.pos = dst }
40 def disappear(item, name = "disappear")
42 SimpleAnimation.new name, LENGTH,
43 lambda { item.opacity = 1.0; item.visible = true },
44 lambda {|t| item.opacity = 1.0 - t },
45 lambda { item.remove }
49 def appear(item, name = "appear")
50 SimpleAnimation.new name, LENGTH,
51 lambda { item.opacity = 0.0; item.visible = true },
52 lambda {|i| item.opacity = i },
53 lambda { item.opacity = 1.0 }
56 def instant_appear(p, piece, name = "appear")
57 Animation.new(name) { board.add_piece p, piece }
60 def instant_disappear(p, name = "disappear")
61 Animation.new(name) { board.remove_item p }
66 Linear = Factory.new do |src, dst|
68 lambda {|i| delta * i }
72 FACTOR = Math.exp(3.0) - 1
73 def initialize(src, dst)
75 nonlin = lambda{|i| (Math.exp(3.0 * i) - 1) / FACTOR }
77 if @delta.x.abs < @delta.y.abs
87 Qt::PointF.new(@delta.x * @x[i], @delta.y * @y[i])