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
Rotate (Read 760 times)
Rotate
Sep 29th, 2009, 5:03pm
 
For the life of me I cannot find what is wrong with the code I wrote. It is meant to rotate (spin) Zoog on the center but for some reason he moves around the center. I've tried comparing to the example but it looks exactly the same to me. Maybe another set of eyes can catch what I can't.





float theta = 0.0;

void setup () {
 size (200, 200);
}

void draw() {
 background (255);

translate (width/2,height/2);
rotate (theta);
 ellipseMode (CENTER);
 rectMode (CENTER);

// Zoog's Body
stroke (0);
fill (150);
rect (100, 100, 20, 100);

//Zoog's head
stroke (0);
fill (255);
ellipse (100, 70, 60, 60);

//Zoog's eyes
fill (0);
ellipse (81, 70, 16, 32);
ellipse (119, 70, 16, 32);

//Zoog's legs
line (90, 150, 80, 160);
line (110, 150, 120, 160);


theta += 0.02;
}
Re: Rotate
Reply #1 - Sep 29th, 2009, 5:23pm
 
the problem is, that you draw your Zoog in the middle of the screen, but processing rorates arround (0,0); that means you have to translate it, and then rotate it. and then translate back to the middle

so just add another translate (-width/2,-height/2);
and it should work
Re: Rotate
Reply #2 - Sep 29th, 2009, 5:25pm
 
Wow, I could have sworn I tried that and it didn't work. Maybe another little mistake on my part. Thank you very much. Saved me hours of misery.
Page Index Toggle Pages: 1