1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'animation_field'
14 def group(*animations)
15 unless animations.empty?
16 anim = animations.dup.compact
17 return nil if anim.empty?
22 "group (#{anim.map{|a| a.to_s}.join(',')})"
24 Animation.new(name) do |i|
33 def sequence(*animations)
34 anim = animations.dup.compact
35 return nil if anim.empty?
40 "sequence (#{anim.map{|a| a.to_s}.join(',')})"
42 Animation.new(name) do |i|
50 def movement(item, src, dst, path_factory)
52 name = "move to #{dst}"
59 dst = board.to_real(dst)
60 path = path_factory.new(src, dst)
62 SimpleAnimation.new name, LENGTH,
63 lambda { board.raise(item) },
64 lambda {|i| item.pos = src + path[i] },
65 lambda { item.pos = dst; board.lower(item) }
69 def disappear(item, name, opts = { })
72 Animation.new(name) { item.visible = false; true }
74 SimpleAnimation.new name, LENGTH,
75 lambda { item.opacity = 1.0; item.visible = true },
76 lambda {|t| item.opacity = 1.0 - t },
77 lambda { item.remove }
82 def appear(item, name, opts = { })
84 Animation.new(name) { item.opacity = 1.0; item.visible = true; true }
86 SimpleAnimation.new name, LENGTH,
87 lambda { item.opacity = 0.0; item.visible = true },
88 lambda {|i| item.opacity = i },
89 lambda { item.opacity = 1.0 }
95 Linear = Factory.new do |src, dst|
97 lambda {|i| delta * i }
101 FACTOR = Math.exp(3.0) - 1
102 def initialize(src, dst)
104 nonlin = lambda{|i| (Math.exp(3.0 * i) - 1) / FACTOR }
105 lin = lambda {|i| i }
106 if @delta.x.abs < @delta.y.abs
116 Qt::PointF.new(@delta.x * @x[i], @delta.y * @y[i])