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 › restart/reset sketch
Page Index Toggle Pages: 1
restart/reset sketch (Read 2022 times)
restart/reset sketch
Dec 3rd, 2007, 7:13pm
 
hi all!

what possibilities exists to restart or reset a sketch to its initial status (nothing drawn)? do i need to reset all variables and arrays "manually"?
i would like to run my animation in an endless loop, but restarting after a defined amount of time.

btw. is there a way to make a clock running backwards as visual timer on the screen (like -2:36)?

thanks a lot!

regards,
daniel
Re: restart/reset sketch
Reply #1 - Dec 3rd, 2007, 8:06pm
 
hi,
just call the setup() method! if you do initialize your variables and arrays in setup() - it's here for that - then it will reset your app.
Re: restart/reset sketch
Reply #2 - Oct 18th, 2009, 7:44am
 
How do you 'call' a function? - I'm looking to do the same as above. Cheers! L.
Re: restart/reset sketch
Reply #3 - Oct 18th, 2009, 8:29am
 
just a stupid example...

declare your variables outside setup. set them in setup... draw whatever you want. and on mouseclick, i call setup again and reset the variables/sketch



float x;
float y;
float r;

void setup(){
size(400,400);
x=1;
y=1;
r=1;  
}

void draw(){
background(0);
x+=0.8;
y+=0.8;
r+=0.1;
if(x>width){
 x=0;
 y=0;
}

fill(255,0,0);
ellipse(x,y,r,r);
}

void mouseClicked(){
setup();
}

Page Index Toggle Pages: 1