Search code examples
mathluaheartrate

Converting heart beat rate to animate pulsing graphic


My maths is terrible. The graphic must pulse synced to HR. The pulsing is controlled by an opacity value that maxes out at 100=fully opaque and starts at 0=transparent. So i need to ramp up to 100 in fractions and back down again and repeat all using a function that gets called once a millisecond.

E.g.
I have bpm as 50
Per second is 60/50=1.2
Per millisecond as 1.2/1000=0.0012
Then 100 (the max opaque value)/0.0012 = 83,333 steps to get to 100 in increments of 0.0012 ????


Solution

  • a function that gets called once a millisecond

    No way!

    I suggest calling your function much, much slower and ramping the transparency with larger increments - the visual effect will be identical.

    Suggest calling your function 10 times per second.