Created
November 12, 2013 21:23
-
-
Save hems/7438971 to your computer and use it in GitHub Desktop.
A simple Coffee Script LFO to run on the browser. Useful for animations and modulations. # - performance.now() will return browser microsecond precision when possible
# - if you wish to use outside of the browser just use some other timing source instead of "performance.now()" # - parameter "speed" could use a more comprehensive time unit, "ms" …
This file contains hidden or 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
# | |
# If you wish to have a landscape "8" movement, like the "infinity sign" you should use something like: | |
# lfo = new LFO 1 | |
# lfo_y = new LFO 0.5 | |
# | |
# Then if you wish to make it slower, multiply both by same value | |
# | |
# lfo = new LFO 1 * 2 | |
# lfo_y = new LFO 0.5 * 2 | |
# | |
performance = performance || {}; | |
performance.now = | |
performance.now || | |
performance.mozNow || | |
performance.msNow || | |
performance.oNow || | |
performance.webkitNow || | |
-> return Date.now() | |
module.exports = class LFO | |
frame: null | |
# function responsible for the easing. | |
# function will receive time values and generate numbers from -1 to 1 | |
funk: null | |
constructor: ( @speed = 1, @funk = Math.sin ) -> | |
@reset() | |
@speed = @speed * 1000 | |
funk = Math.sin | |
reset: -> | |
@frame = 0 | |
tick: ( gain = 1 ) -> | |
@frame++ | |
return @funk ( performance.now() / @speed ) * gain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment