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 & HelpPrograms › How to restart my skeych by clicking on it
Page Index Toggle Pages: 1
How to restart my skeych by clicking on it ? (Read 395 times)
How to restart my skeych by clicking on it ?
Dec 17th, 2008, 7:48pm
 
Hi , i have uploaded to my web one sketch, i want to make it possible to start,restart or pause it when the user clicks on it with the LMB.


How do i do this ?

Thanx !
Re: How to restart my skeych by clicking on it ?
Reply #1 - Dec 18th, 2008, 8:28pm
 
The Examples > Topics > Cellular automata > Spore1 shows how to reset the sketch with LMB (or right one, actually).

You can modify it as follow:
Code:
// Top of code
boolean stop;
//[...]
void draw() {
if (stop) return;
// Same code
}
//[...]
void mousePressed()
{
if (mouseButton == LEFT) {
stop = !stop;
} else if (mouseButton == RIGHT) {
numcells = 0;
setup();
}
}
Re: How to restart my skeych by clicking on it ?
Reply #2 - Dec 19th, 2008, 4:22pm
 
Thanx ! but i have done something a bit differerent, i have told processing to erase everything that was painted with this code :

Code:
 if (mousePressed==true)
 background(#FA0058);



In my bouncing ball sketch http://www.tweakingknobs.com/63.html this is what i want.

But in the many bouncing rects i want it the other way round.

So, whith the many bouncing rects i want that is always not leaving trails, but when you click on it it leaves trails.

I have tried , but i cant make it, do you know how ?
Here's the code

Code:
// many bouncing bal program 

// global variables

int ballCount = 500;
int ballSize = 18;
int ballSpeed =3;
float []xspeed = new float [ballCount];
float []yspeed = new float [ballCount];
float []xpos = new float [ballCount];
float []ypos = new float [ballCount];
float []wdth = new float [ballCount];
float[]ht = new float [ballCount];

//initialize sketch
void setup(){
 
 
 size (800,300);
 background(#FA0058);
noStroke();
frameRate(30);
smooth();
 //initialize values for all balls
 
 for (int i=0; i<ballCount; i++) {
 
 // set variable ball speed
 
 xspeed[i] = random(1, ballSpeed);
 yspeed[i] = random (-ballSpeed, ballSpeed);
 
 //ball varied ball sizes
 
 wdth[i] = random(1, ballSize);
 ht[i] = wdth[i];
 
 // set initial ball placement
 
 xpos[i] = width/2+random(-width/3, width/3);
 ypos[i] = height/2+random(-height/3, height/3);
}
}
// turnoff stroke




// draw

void draw(){

 

 // updates background;
   if (mousePressed==true)
 background(#FA0058);
 
 
 
 
 for(int i=0; i<ballCount; i++){
  // fill(#FA0058,25);
  //rect (width/2,height/2,width,height)
  fill(255);
   //drawballs
 
  rect (xpos[i],ypos[i], wdth[i],ht[i]);
   
  // upgrade ball pos
  xpos[i]+=xspeed[i];
  ypos[i]+=yspeed[i];
 
  // conditionals
  if (xpos[i]+wdth[i]/2>=width || xpos[i]<=wdth[i]/2){
    xspeed[i]*=-1;
  }
  if (ypos[i]+ht[i]/2>=height || ypos[i]<=ht[i]/2){
    yspeed[i]*=-1;
   
  }
 }
}
Re: How to restart my skeych by clicking on it ?
Reply #3 - Dec 19th, 2008, 6:49pm
 
You are almost there, my friend.
Change the line to
if (mousePressed==false)

or simply
if (!mousePressed)

That will draw trails while holding the mouse button.
Re: How to restart my skeych by clicking on it ?
Reply #4 - Dec 19th, 2008, 7:00pm
 
Thank you very much my friend ! Its working now as i wanted, now i have to keep on learning more processing Grin
Page Index Toggle Pages: 1