Method: MathUtils.sinwave

Defined in:
lib/math_utils.rb

.sinwave(detail = 2048, saturation = 0) ⇒ Object

generates data for sin wave in an array (single cycle)

detail

number of elements in the wave.

default: 2048 very smooth



28
29
30
31
32
33
34
35
36
37
# File 'lib/math_utils.rb', line 28

def self.sinwave(detail = 2048, saturation=0)
  raise "Sinwave frames must be specifed as >= 3." if detail < 3
  val = Array.new(detail)
  val.each_with_index do |foo,i|
    progress=i.to_f/detail
    val[i] = Math.sin(2.0*Math::PI*progress)
    val[i] = (val[i]-saturation.to_f)+rand*saturation.to_f*2.0
  end
  val
end