Class: DYI::Animation::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/dyi/animation.rb

Overview

This class is abstract.

Base class for animation classes.

Since:

  • 1.0.0

Direct Known Subclasses

PaintingAnimation, TransformAnimation

Constant Summary collapse

IMPLEMENT_ATTRIBUTES =

Since:

  • 1.0.0

[:from, :to, :duration, :begin_offset,
:begin_event, :end_offset, :end_event, :fill,
:additive, :restart, :relays, :relay_times,
:calc_mode, :repeat_count, :key_splines]
VALID_VALUES =

Since:

  • 1.0.0

{
  :fill => ['freeze','remove'],
  :additive => ['replace', 'sum'],
  :restart => ['always', 'whenNotActive', 'never'],
  :calc_mode => ['discrete', 'linear', 'paced', 'spline']
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shape, options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • shape (Shape::Base)

    a target element for an animation

  • options (Hash)

    an option for an animation

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/dyi/animation.rb', line 194

def initialize(shape, options)
  raise ArgumentError, "`:to' option is required" unless options.key?(:to)
  @shape = shape
  options.each do |attr, value|
    if IMPLEMENT_ATTRIBUTES.include?(attr.to_sym)
      __send__("#{attr}=", value)
    end
  end
  @relays ||= []
  @relay_times ||= []
end

Instance Attribute Details

#additive=(value) ⇒ Object (writeonly)

+++ +++ +++

Parameters:

  • value (String)

    the value of attribute fill

  • value (String)

    the value of attribute additive

  • value (String)

    the value of attribute restart

  • value (String)

    the value of attribute calc_mode

Since:

  • 1.3.0



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/dyi/animation.rb', line 132

VALID_VALUES.each do |attr, valid_values|
  define_method("#{attr.to_s}=") {|value|
    if (value = value.to_s).size == 0
      instance_variable_set("@#{attr}", nil)
    else
      unless VALID_VALUES[attr].include?(value)
        raise ArgumentError, "`#{value}' is invalid #{attr}"
      end
      instance_variable_set("@#{attr}", value)
    end
  }
end

#calc_mode=(value) ⇒ Object (writeonly)

+++ +++ +++

Parameters:

  • value (String)

    the value of attribute fill

  • value (String)

    the value of attribute additive

  • value (String)

    the value of attribute restart

  • value (String)

    the value of attribute calc_mode

Since:

  • 1.3.0



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/dyi/animation.rb', line 132

VALID_VALUES.each do |attr, valid_values|
  define_method("#{attr.to_s}=") {|value|
    if (value = value.to_s).size == 0
      instance_variable_set("@#{attr}", nil)
    else
      unless VALID_VALUES[attr].include?(value)
        raise ArgumentError, "`#{value}' is invalid #{attr}"
      end
      instance_variable_set("@#{attr}", value)
    end
  }
end

#fill=(value) ⇒ Object (writeonly)

+++ +++ +++

Parameters:

  • value (String)

    the value of attribute fill

  • value (String)

    the value of attribute additive

  • value (String)

    the value of attribute restart

  • value (String)

    the value of attribute calc_mode

Since:

  • 1.3.0



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/dyi/animation.rb', line 132

VALID_VALUES.each do |attr, valid_values|
  define_method("#{attr.to_s}=") {|value|
    if (value = value.to_s).size == 0
      instance_variable_set("@#{attr}", nil)
    else
      unless VALID_VALUES[attr].include?(value)
        raise ArgumentError, "`#{value}' is invalid #{attr}"
      end
      instance_variable_set("@#{attr}", value)
    end
  }
end

#key_splines=(value) ⇒ Object (writeonly)

Parameters:

  • keys (Array<#to_f>)

Since:

  • 1.3.0



182
183
184
# File 'lib/dyi/animation.rb', line 182

def key_splines=(keys)
  @key_splines = keys.map{|time| time.to_f}
end

#relays=(value) ⇒ Object (writeonly)

Parameters:

  • times (Array<#to_f>)

Since:

  • 1.3.0



175
176
177
# File 'lib/dyi/animation.rb', line 175

def relay_times=(times)
  @relay_times = times.map{|time| time.to_f}
end

#repeat_count=(value) ⇒ Object (writeonly)

Parameters:

  • count (#to_f)

Since:

  • 1.3.0



152
153
154
# File 'lib/dyi/animation.rb', line 152

def repeat_count=(count)
  @repeat_count = count.to_f
end

#restart=(value) ⇒ Object (writeonly)

+++ +++ +++

Parameters:

  • value (String)

    the value of attribute fill

  • value (String)

    the value of attribute additive

  • value (String)

    the value of attribute restart

  • value (String)

    the value of attribute calc_mode

Since:

  • 1.3.0



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/dyi/animation.rb', line 132

VALID_VALUES.each do |attr, valid_values|
  define_method("#{attr.to_s}=") {|value|
    if (value = value.to_s).size == 0
      instance_variable_set("@#{attr}", nil)
    else
      unless VALID_VALUES[attr].include?(value)
        raise ArgumentError, "`#{value}' is invalid #{attr}"
      end
      instance_variable_set("@#{attr}", value)
    end
  }
end

Instance Method Details

#accumulate=(value) ⇒ Object

Parameters:

  • value (Boolean)

Since:

  • 1.3.0



188
189
190
# File 'lib/dyi/animation.rb', line 188

def accumulate=(value)
  @accumulate = value
end

#accumulate?Boolean

Returns whether the animation is cumulative.

Returns:

  • (Boolean)

    true if the animation is cumulative, false otherwise

Since:

  • 1.3.0



116
117
118
# File 'lib/dyi/animation.rb', line 116

def accumulate?
  @accumulate ? true : false
end

#begin_event=(event) ⇒ Object

Since:

  • 1.0.0



160
161
162
# File 'lib/dyi/animation.rb', line 160

def begin_event=(event)
  @begin_event = event
end

#begin_offset=(offset) ⇒ Object

Since:

  • 1.0.0



156
157
158
# File 'lib/dyi/animation.rb', line 156

def begin_offset=(offset)
  @begin_offset = offset.to_f
end

#duration=(duration) ⇒ Object

Since:

  • 1.0.0



145
146
147
# File 'lib/dyi/animation.rb', line 145

def duration=(duration)
  @duration = duration.to_f
end

#end_event=(event) ⇒ Object

Since:

  • 1.0.0



168
169
170
# File 'lib/dyi/animation.rb', line 168

def end_event=(event)
  @end_event = event
end

#end_offset=(offset) ⇒ Object

Since:

  • 1.0.0



164
165
166
# File 'lib/dyi/animation.rb', line 164

def end_offset=(offset)
  @end_offset = offset.to_f
end

#relay_times=(times) ⇒ Object

Parameters:

  • times (Array<#to_f>)

Since:

  • 1.3.0



175
176
177
# File 'lib/dyi/animation.rb', line 175

def relay_times=(times)
  @relay_times = times.map{|time| time.to_f}
end