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 › simple program trouble
Page Index Toggle Pages: 1
simple program trouble (Read 445 times)
simple program trouble
Sep 6th, 2009, 6:45pm
 
the program is supposed to draw a line with the width changing with the speed of the mouse. also the line is supposed to turn white when it goes over a black spot.
sorry im awful at explaining, please write back.




// program by jake lalalla

color co = color(0);
color cp = get(mouseX, mouseY);

void setup() {
 size(1920, 1200);
 background(255);
 smooth();
}

void draw() {
 stroke(0);
 strokeWeight(abs(pmouseX - mouseX));
 line(pmouseX, pmouseY, mouseX, mouseY);
 if (cp == co) {
   stroke(255);
 }
 else {
   stroke(0);
 }
}
Re: simple program trouble
Reply #1 - Sep 6th, 2009, 7:58pm
 
At the point you're creating that cp variable, the preprocessor can't deal with mouseX and mouseY yet, because they don't exist until your program starts.  You also want cp to be dynamic and change with each frame, so it needs to be in draw().  Also, the abs(mouseX-pmouseX) is just measuring horizontal distance...you can use dist() or a Pythagorean distance formula.

Quote:
color co = color(0);
color cp;

void draw() {
 stroke(0);
 strokeWeight(dist(pmouseX,pmouseY,mouseX,mouseY));
 line(pmouseX, pmouseY, mouseX, mouseY);
 cp = get(mouseX, mouseY);
 // etc...
}


--Ben
Page Index Toggle Pages: 1