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 › 2 things rotate around 2 separate centers
Page Index Toggle Pages: 1
2 things rotate around 2 separate centers? (Read 1055 times)
2 things rotate around 2 separate centers?
Dec 29th, 2008, 11:28am
 
Hi there

I'm trying to write a program, which should have 2 objects on the screen, both rotating around their own y-axis (with P3D). how can i do that? everything i tried so far resulted in the left one turning correctly but the second one turning around the first one. is it possible for the second object not to be affected by the first translate-command or something like that?
Re: 2 things rotate around 2 separate centers?
Reply #1 - Dec 29th, 2008, 1:36pm
 
Example:
Code:
void setup()
{
size(500, 500);
smooth();
ellipseMode(CENTER);
}

float angle;

void draw()
{
background(55);
angle += PI/180;

// Save defaults
pushMatrix();
// Move origin
translate(width*0.325, height*0.325);
// Rotate
rotate(angle);
// And draw
DrawFace1();
// Restore defaults: next drawing is independent
popMatrix();

pushMatrix();
translate(width*0.68, height*0.68);
rotate(-angle);
DrawFace2();
popMatrix();
}

void DrawFace1()
{
noStroke();
fill(#FFFF00);
// Draw around the origin
ellipse(0, 0, width/2, height/2);
fill(0);
ellipse(-width/8, -height/8, width/16, height/8);
ellipse(+width/8, -height/8, width/16, height/8);
strokeWeight(8);
stroke(0);
noFill();
arc(0, 0, width/3, height/3, PI*0.2, PI*0.8);
}

void DrawFace2()
{
noStroke();
fill(#FFAAEE);
// Draw around the origin
ellipse(0, 0, width/2, height/2);
fill(255);
ellipse(-width/8, -height/16, width/6, height/12);
ellipse(+width/8, -height/16, width/6, height/12);
fill(#8888FF);
ellipse(-width/8, -height/16, width/12, height/12);
ellipse(+width/8, -height/16, width/12, height/12);
strokeWeight(8);
stroke(#FF2200);
noFill();
arc(0, height/4, width/3, height/3, PI*1.3, PI*1.7);
}
Re: 2 things rotate around 2 separate centers?
Reply #2 - Dec 29th, 2008, 7:25pm
 
perfect! thank you for the fast answer! Cheesy
and cute faces by the way Wink
Page Index Toggle Pages: 1