Skip to content

Instantly share code, notes, and snippets.

@watzon
Created April 26, 2020 22:30
Show Gist options
  • Save watzon/85464c5254f93cf855fffcc100f6fc4f to your computer and use it in GitHub Desktop.
Save watzon/85464c5254f93cf855fffcc100f6fc4f to your computer and use it in GitHub Desktop.
Simple Wave Functions
def sine(input, amplitude, phase, frequency = nil, angular_frequency = nil)
if frequency
amplitude * Math.sin(2 * Math::PI * frequency * input + phase)
elsif angular_frequency
amplitude * Math.sin(angular_frequency * input + phase)
else
raise "Either frequency or angular_frequency is required"
end
end
# For given running `input`, `amplitude`, and `period`
# generates a triangle wave.
def triangle(input, amplitude, period)
hp = p / 2
(a / p) * (p - (x % (2 * p) - p).abs)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment