Created
April 26, 2020 22:30
-
-
Save watzon/85464c5254f93cf855fffcc100f6fc4f to your computer and use it in GitHub Desktop.
Simple Wave Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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