jonathanhogg / flitter

A functional programming language and declarative system for describing 2D and 3D visuals
https://flitter.readthedocs.io
BSD 2-Clause "Simplified" License
34 stars 1 forks source link

Counters annoy me #47

Closed jonathanhogg closed 4 months ago

jonathanhogg commented 4 months ago

I dislike that counter() is a function with side-effects. The proper thing should be that counters become very simple renderers. Something like:

!counter state=key rate=0 [ time=frame-time ] [ initial=0 ]

If key isn't found in the state then it is initialised with the value of initial and time is recorded at key;:time. Each frame I calculate the delta between time and the last value from the state and then multiply this by rate and add it to the current key value in the state. I can just use normal vector multiplication and addition here so n-vectors are supported automatically.

Interestingly, rate, time and initial cannot be explicitly null – any of them being null is the same as the attribute being unset and therefore the default value. However, any of them could be non-numeric, which would result in a null calculation, so I'm going to assume that non-numeric vectors are implicitly null, and ignore them.

If I'm going to change counters, I should do so before 1.0.0.