We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How to create a "value ramp"
Page Index Toggle Pages: 1
How to create a "value ramp" ? (Read 321 times)
How to create a "value ramp" ?
Dec 9th, 2008, 3:14am
 
Hi There !

I'm totally new with processing and this is my first try (I just finished on tutorials ^^ ), so my problem maybe very simple, but I'm trying to create a ramp between 2 values. In fact I don't how it's called in processing, I use to work with PureData, and in PureData it's called a ramp :

for example, how to turn a value X into -X within 5 seconds (to make it smoother) ?

I tried something like this :
       
        for(float i=0; i<abs(x);i=i+0.1){
        x  -=  i;  }

but it seems that it generate many values at the same times and not create a linear variation from x to -x.

if anyone has an idea, please give me a hand ^^
Re: How to create a "value ramp" ?
Reply #1 - Dec 9th, 2008, 10:52am
 
It think something like:

Code:
float tmpx=lerp(X,-X,millis()/5000.0);


will give you a linearly changing value from X to -X over 5 seconds from the program starting.

To do it from an arbitrary point in time:

Code:
int startmillis=5000; //5 seconds in, or you could make this the current value of millis() at a keypress.

float tmpx=lerp(X,-X,(millis()-startmillis)/5000.0);

Re: How to create a "value ramp" ?
Reply #2 - Dec 11th, 2008, 2:30am
 
Thanks for your answer Smiley

in fact I didn't manage to do it this way, but I get a good result with something like this :

if (x > x_ecran-50){
        xv = xv-(4/r);}
      if(x < 50){
        xv = xv+(4/r);}

(xv is speed value, and r is size value)

cause in fact I was trying to make a smooth speed reversion when my object go outside the screen) so everything is ok ^^
Page Index Toggle Pages: 1