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 › Quick question about a simple animation.
Page Index Toggle Pages: 1
Quick question about a simple animation. (Read 533 times)
Quick question about a simple animation.
Apr 14th, 2009, 5:03pm
 
Sorry to bother someone with this question. I am new to processing (2nd day to be exact) and I am trying to do a simple animation.  Basically what I am trying to do is make an ellipse appear when you click the mouse. (I have been successful thus far). Then once the mouse is clicked again and a second ellipse appears, I want that 2nd ellipse to connect to the 1st with a line...much like a connect-the-dots sort of thing.

I basically want it to look like this...but like i said i want the lines to connect wherever I click the mouse.

void setup() {
size(640, 360);
background(102);
smooth();
fill(0, 102);
}


void draw() {
if (mousePressed) {
  fill(255);
  ellipse(mouseX, mouseY, 9, 9);
  line(mouseX,mouseY,mouseX+100,mouseY);
  ellipse(mouseX+100,mouseY,9,9);
}
}

I know, it's simple and stupid but it's bugging me and help would be much appreciated Smiley

Thanks!
Re: Quick question about a simple animation.
Reply #1 - Apr 14th, 2009, 6:42pm
 
I don't have Processing installed on this PC, so I can't test this... but I'll just try to write it out and hope it helps (and works).

Code:

float xval, yval;
boolean firstclick = true;

void setup() {
size(640, 360);
background(102);
smooth();
fill(0, 102);
}

void draw() {
if (mousePressed) {
 fill(255);
 ellipse(mouseX, mouseY, 9, 9);
 if (firstclick == true){
    xval = mouseX;
    yval = mouseY;
    firstclick = false;
  }
  else {
    line(xval, yval, mouseX, mouseY);
    xval = mouseX;
    yval = mouseY;
   }
 }
}
Re: Quick question about a simple animation.
Reply #2 - Apr 14th, 2009, 7:47pm
 
you nailed it!

Looks like I wasn't as close as I thought I was Tongue

Thank you!

Page Index Toggle Pages: 1