davidedc / livecodelab

a web based livecoding environment
http://livecodelab.net/
MIT License
327 stars 63 forks source link

"beat" and "pulse" to also accept a parameter like wave does / change parameter from period to frequency #222

Closed davidedc closed 10 years ago

davidedc commented 10 years ago

there should be a way to modify the beat and pulse values just like wave, so it will be possible to have, say, a box flashing twice as fast as another one.

Also I'd probably change from specifying the period to specifying the frequency. I think it's more natural to have "more flashing" with higher numbers rather than the opposite.

beat: ->
  passed = new Date().getTime() - @lastBeat
  return @beatCount + passed / @mspb;

pulse: ->
  return Math.exp(-Math.pow( Math.pow(@beat() % 1, 0.3) - 0.5, 2) / 0.05)

# Wave: simple harmonic motion where a is period in milliseconds
wave: (period) ->
  if typeof period isnt "number"
    period = 1
  sin((@beat()/period) * Math.PI)
noio commented 10 years ago

Good call.

I never liked wave myself, because it is little more than just a sine (is sin really that scary? ;) ), and move doesn't even default to just move wave because it needs both a sin and a cos. But, you are right that, at the very least, frequency is more sensible than period.

Regarding beat however, can simply be sped up doing beat * 2. "Longening" that to beat(2) makes little sense, and it obfuscates what beat actually means.

For pulse I will introduce a single argument that multiplies the beat() call by that number, so pulse(2) will result in pulsing twice as fast.