Count up & down, up & down - using maths?

DigiChainDigiChain 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

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited February 2013
    0, 1, 2, 3, 2, 1, 0, 1, 2...=
    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)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Way to go, RT!! :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @gyroscope -- It was from a quick google search using "modulo waveform" as the search terms. I recognized the pattern as a triangle waveform and was interested if one could do it with the modulo operator.

    Google is our friend!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2013

    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

  • LumpAppsLumpApps Member Posts: 2,881
    So cool. I am liking math more and more ;)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Thats the same formula i used to 'rotate' the falcons in grisly manor ;)
  • DigiChainDigiChain Member, PRO Posts: 1,288
    Excellent - great stuff! Thanks @RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Glad it's useful!
  • DigiChainDigiChain Member, PRO Posts: 1,288
    Ok - follow up question:

    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...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Here is a demo file:
  • SocksSocks London, UK.Member Posts: 12,822
    Here is a demo file:
    Excellently great !
  • DigiChainDigiChain Member, PRO Posts: 1,288
    Here is a demo file:
    Cheers!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited February 2013
    Hey @Socks,
    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.
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2013
    Hey @Socks,
    That was your 1000th post! Congratulations on making it thus far!
    I didn't realise ! How did you know ? I'm going to celebrate by getting totally wasted, I've just bought 4 litres of the cheapest red wine I could find - just setting up the intravenous feed now . . .
    But I honestly can't think of one that hasn't already been addressed by the great contributors on this forum!
    Why is a raven like a writing desk ?
    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.)
    Actually, the hitch appears in the last 10% of the last whole number value, so while it's 10% of an alpha fade from 1 to 0 (or 0 to 1) and an audio ramp from 1 to 0 (or 0 to 1), it's a small fraction of an interpolated move across 100 pixels and 50% of an interpolation from 0.2 to 0.4

    [/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

    . . . .
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2013

    Why is a raven like a writing desk ?
    Other people's writing desks, I can't answer for. But my writing desk: it's black with carved wooden feather ornaments, and it will push its drawers in and out in a pathetic imitation of flapping wings, always at the most inappropriate times, all the while emitting a high-pitched squawking noise. It really is off-putting.

    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

  • SocksSocks London, UK.Member Posts: 12,822
    I'lg khad a certains pRecentarge (`Hactual amount classssified) of a battle of whine thonight, although I droubt Hanyone wrould Hever know, hass i not did the sailing.
    8-X
    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.... :>
    ;)
  • LumpAppsLumpApps Member Posts: 2,881
    Here is a version of @RThurman s demo without timers and less Attributes but with a constrain behaviour. (I added the constrain behaviour in the actor and turned the timer off).
    I am not saying this is better but it suited my needs a little more and thought I'd share :)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @LudwigHeijden -- nice use of built-in time. Your implementation is elegantly simple. (Just like good GameSalad logic should be!)
Sign In or Register to comment.