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 › Resetting issue [RESOLVED]
Page Index Toggle Pages: 1
Resetting issue [RESOLVED] (Read 442 times)
Resetting issue [RESOLVED]
Jul 13th, 2008, 5:10am
 
Hi, I'm completely new to processing, and I want to be able to reset my program without having to close it and reopen it again. I've searched the examples and references but I can't seem to find anything about it anywhere.

I just want to assign it to "keyPressed() {" or something to reset my sketch.

Thanks in advance.
Re: Resetting
Reply #1 - Jul 13th, 2008, 9:49am
 
It depends on what you call "reset".
If that's to go back to the initial state, it depends on your program.
Basically, it needs to reset all variables to the initial state, which can be done perhaps by calling setup() yourself.
Supposing you don't do static inits.

Another simple way is to put most init code in a function or a class, and call this function or create a new instance of the class to replace the previous one.
Re: Resetting
Reply #2 - Jul 13th, 2008, 10:14am
 
I'm afraid it only half solved the problem.

The canvas is cleared, but in my sketch the floats are modified and they remain modified when setup is called.
Also, I have floats determined by random, which do not reset to a new random number when setup is called.

my coding:

//Webber by Zander Hulme | built with Processing 0135 Beta
void setup() {
 size(600, 600);
 stroke(255);
 noFill();
 background(0);
 smooth();
 stroke(R, G, B);
 frameRate(30);
 strokeWeight(0.25);
}
float a = random(150);
float b = random(120);
float c = random(200);
float x = random(550);
float y = random(550);
float R = random(255);
float G = random(255);
float B = random(255);
float cosine;

void draw() {
 if(mousePressed) {
 a = a*1.5;
 b = b/2;
 if(y >= height/2) {
 rotate(b*(0-a));
 } else {
   rotate(b*a);
}}
 ellipse(x, y, a, a);
 ellipse(x, y, a, b);
 ellipse(x, y, a, c);
 ellipse(x, y, cosine, a);
 ellipse(x, y, b, a);
 ellipse(x, y, b, b);
 ellipse(x, y, b, c);
 ellipse(x, y, c, a);
 ellipse(x, y, c, b);
 ellipse(x, y, c, c);
 ellipse(x, y, c, cosine);
}
Re: Resetting
Reply #3 - Jul 13th, 2008, 10:41am
 
When you globally define things, values are stored so I believe your problem is in there. You can reset and call them again, but you'll add up with the values that where generated the first time. Try putting it in functions (maybe grouping them in a Class) and try out different places where you define the variables. If you define the variables in the function itself, then everytime you call the function the variables should be reseted also.

I had the same problem last night, only I lost the variables and I actually wanted to store them. This is what worked for me.
Re: Resetting
Reply #4 - Jul 13th, 2008, 2:28pm
 
i wrote on Jul 13th, 2008, 9:49am:
Supposing you don't do static inits.
Wink

You do precisely that. Just declare the float variables, and set them to random values in the setup() (or group them in another function).
Re: Resetting
Reply #5 - Jul 13th, 2008, 2:57pm
 
Thanks for your help, but when I move my float values into functions, (as below) other functions don't work and they need to be moved all-over the place, and after that it doesn't do the same thing as it used to. I plan to purchase a book on processing soon, so I may be able to re-write it to work better. Anyway, thank you again for your help and I hope to see some of all of your sketches in the exhibition thread!

//Webber
void setup() {
 size(600, 600);
 stroke(255);
 noFill();
 background(0);
 smooth();
 stroke(random(255), random(255), random(255));
 frameRate(30);
 strokeWeight(0.25);
 float a = random(150);
float b = random(120);
float c = random(200);
}

float cosine;

void draw() {
 if(mousePressed) {
   float a = random(150);
   float b = random(120);
   float y = random(550);
 a = a*1.5;
 b = b/2;
 if(y >= height/2) {
 rotate(b*(0-a));
 } else {
   rotate(b*a);
float x = random(550);
}
float c = random(200);
float x = random(550);
 ellipse(x, y, a, a);
 ellipse(x, y, a, b);
 ellipse(x, y, a, c);
 ellipse(x, y, cosine, a);
 ellipse(x, y, b, a);
 ellipse(x, y, b, b);
 ellipse(x, y, b, c);
 ellipse(x, y, c, a);
 ellipse(x, y, c, b);
 ellipse(x, y, c, c);
 ellipse(x, y, c, cosine);
}}

void keyPressed() {
 setup();
}
Re: Resetting
Reply #6 - Jul 13th, 2008, 3:38pm
 
You need to separate the definition of the variable, and the setting of the value, these are 2 separate stages.

e.g.
Code:

float a;

void setup()
{
size(300,200);
a=12;
}

void draw()
{
//use a somehow.
}
Re: Resetting
Reply #7 - Jul 14th, 2008, 4:23am
 
Huzzah! Brilliant! It does exactly what I wanted it to now! Cheers JohnG! "Webber" May appear in the exhibition thread soon, after some modifications.
Page Index Toggle Pages: 1