Count up & down, up & down - using maths?
DigiChain
Member, PRO Posts: 1,288
Hi guys, I'm wondering if one of you maths whizzes knows a simple formula to count up and down through a set range of numbers.
So for example - (value+1)%4 would give me - 0, 1, 2, 3, 0, 1, 2, 3, 0, 1....
But I want - 0, 1, 2, 3, 2, 1, 0, 1, 2...
Can anyone help?
Cheers
So for example - (value+1)%4 would give me - 0, 1, 2, 3, 0, 1, 2, 3, 0, 1....
But I want - 0, 1, 2, 3, 2, 1, 0, 1, 2...
Can anyone help?
Cheers
Comments
3-abs((value+1)%(2*3)-3)
0,1,2,3,4,3,2,1,0,1,2,3,4...=
4-abs((value+1)%(2*4)-4)
Way to go, RT!! :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Google is our friend!
Excellent stuff - and so agree about Google as a friend (and Wikipedia; couldn't do without that...); I'm still impressed, really :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Lump Apps and My Assets
It doesn't seem to be doing as expected - maybe I've not keyed something in correct but the count I'm getting is:
3-abs((value+1)%(2*3)-3)
0,1,2,3,2,3,2,3,2,3...
That was your 1000th post! Congratulations on making it thus far!
I'm not sure what to do for my 1000th post (coming up). I thought about about asking my first question on the forum. But I honestly can't think of one that hasn't already been addressed by the great contributors on this forum! Maybe I'll post how to roll your own interpolations that don't have the 10% hitch. (And about 10 other variants than the simple ease in / ease out ones.)
Sorry @Digi-chain about the thread digression. I'm glad the demo works for you.
[/pedantry]
You can lose the glitch by dividing up the interpolation range sufficiently:
So for an alpha channel fade - make an attribute, let's call it 'fader', no, let's call it 'Darth Fader' - we want to interpolate the alpha channel up (from transparent to opaque) - so set 'Darth Fader' to 0
. . . .
Interpolate self.'Darth fader' to 255 / Duration 2 seconds / function [whatever you want]
Constrain self.color.alpha to self.'Darth fader'/255
. . . .
I've had a certain percentage (actual amount classified) of a bottle of wine tonight, although I doubt anyone would ever know, had i not said.
Finally, I will bet a vast sum that you will point out that the explanation above is why a writing desk is like a raven, and not the other way around.... :>
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
I am not saying this is better but it suited my needs a little more and thought I'd share
Lump Apps and My Assets