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.
Page Index Toggle Pages: 1
Face Jitter (Read 529 times)
Face Jitter
Aug 26th, 2009, 3:57pm
 
I have been playing with processing for a day or two. I am trying to get a face to jitter when I move my mouse over it, like the tickle program except with a face. However, I can't seem to get it to work. Here is my code: Code:
// A monster face jitters on mouse over.
float x = 200; // X-coordinate of face
float y = 200; // Y-coordinate of face
void setup()
{
size(300, 300);
//
//
background (255);
}
void draw() {
stroke(255);
fill(255);
rect(x, y, width, height);

if ((mouseX >= x) && (mouseX <= x+55) &&
(mouseY >= y-24) && (mouseY <= y))
x += random(-5, 5);
y += random(-5, 5);

stroke(0);
fill(0);
rect (90, 90, 45, 45);
rect (200, 90, 45, 45);
rect (130, 180, 100, 40);


}

I think it is something stupid that I'm doing in my code...
Suggestions?
Re: Face Jitter
Reply #1 - Aug 26th, 2009, 6:08pm
 
yep there is Smiley
there are alot of things that prevent it from running correct.

first is you are changing x and y to make it jitter but your face actually doesnt cointain these variables. there is still a rect that does, but its drawn white, so you cant see it.

do you want it to wander arround? or just to jitter ? cause then you shouldnt continuesly add -5,5 to x,y
and you have to call background in draw again to reset the background everyframe.

what i do now, instead of drawing everypart of your face to a different coordinate is translating the matrix using translate();
that makes it easier to add whatever you want to your face without taking care of the jittering again

it then looks something like this :



void setup(){
 size(400, 400);
}
void draw() {

background (255);
if (mouseX >100 && mouseX < 300 && mouseY >= 100 && mouseY <= 300)
translate(random(-5, 5),random(-5,5));

fill(0);          
 rect(100,100,200,200);
 fill(255);
 rect (140, 120, 45, 45);
 rect (220, 120, 45, 45);
 fill(255,0,0);
 rect (140, 250, 120, 30);
}


and yes you can use variables like x and y and squarewidth. that makes it probably easier to change the things, i just hardcoded it for now
Re: Face Jitter
Reply #2 - Aug 27th, 2009, 4:28am
 
Thanks, that helped alot. It does exactly what I wanted now!
Page Index Toggle Pages: 1