class MTK::Patterns::Lines
A piecewise linear function (see {}) defined in terms of [value, steps_to_reach_value] pairs.
The “steps_to_reach_value” for the first element is ignored and may be omitted, since it takes 0 steps to start.
Protected Instance Methods
advance()
click to toggle source
(see Pattern#advance
)
# File lib/mtk/patterns/lines.rb, line 23 def advance while @step_count >= @steps @step_count = 0 @index += 1 raise StopIteration if @index >= @elements.length @prev = @next next_elem = @elements[@index] if next_elem.is_a? Array @next = next_elem.first @steps = next_elem.last.to_f else @next = next_elem @steps = 1.0 end end @step_count += 1 if @prev and @next # linear interpolation @current = @prev + (@next - @prev)*@step_count/@steps else @current = @next end end
rewind_or_cycle(is_cycling=false)
click to toggle source
(see Pattern#rewind_or_cycle
)
Calls superclass method
# File lib/mtk/patterns/lines.rb, line 14 def rewind_or_cycle(is_cycling=false) @steps = -1 @step_count = -1 @prev = nil @next = nil super end