Module: SplineHelper

Defined in:
lib/spline_helper.rb

Class Method Summary collapse

Class Method Details

.build_spline_node_from_coordinates(coordinates) ⇒ Object

coordinates: list of x,y pairs, where x in [0..1] and y in [0..1]



14
15
16
17
18
19
20
21
22
23
# File 'lib/spline_helper.rb', line 14

def self.build_spline_node_from_coordinates(coordinates)
  spline_node = Audulus.build_simple_node("Spline")
  spline_node["controlPoints"] = coordinates.map { |x, sample|
    {
      "x" => x,
      "y" => sample.to_f,
    }
  }
  spline_node
end

.build_spline_node_from_samples(samples) ⇒ Object

samples: list of values 0..1, assumed to be evenly spaced along the X axis



6
7
8
9
10
11
# File 'lib/spline_helper.rb', line 6

def self.build_spline_node_from_samples(samples)
  coordinates = samples.each_with_index.map {|sample, i|
    [i.to_f/(samples.count-1).to_f, sample]
  }
  build_spline_node_from_coordinates(coordinates)
end