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
rotation (Read 1764 times)
rotation
Jan 20th, 2006, 9:48am
 
Hi,

Maybe someone can help me with the code below. I want the white triangle to turn around its own center with mouseX movement only. How do I do that?

float x, y;

void setup()
{
 size(200, 200);
 x = width/5.0;
 y = height/5.0;
 noStroke();
 framerate(30.0);
 smooth();
}

void draw()
{
 background(51);
 float a = atan2(mouseY-y, mouseX-x);
 
 translate(x, y);
 rotate(a);
 stroke(255, 0, 0);
 curve(500, 200, 0, 0, 300, 300, 500, 200);
 beginShape(POLYGON);
 vertex(100, 20);
 vertex(50, 50);
 vertex(30, 30);
 endShape();
}
Re: rotation
Reply #1 - Jan 20th, 2006, 4:17pm
 
If I understood your question correctly, you'll want the triangle's center point to be set on the origin (0,0) when you translate to the mouse postion. If you want rotation based on the mouse's x pos you can just pass the mouseX value (converted to radians) to rotate(). To increase the rotations based on mouse movement, multiply mouseX by some value, e.g. rotate(radians(mouseX*1.5))  
Try this:
Code:
 
void setup()
{
size(200, 200);
noStroke();
framerate(30.0);
smooth();
}

void draw()
{
background(51);
translate(mouseX, mouseY);
rotate(radians(mouseX)); //multiply mouseX to increase rots
stroke(255, 0, 0);
curve(500, 200, 0, 0, 300, 300, 500, 200);
beginShape(POLYGON);
vertex(35, -15);
vertex(-15, 15);
vertex(-35, -5);
endShape();
}


Hope this helped.

ira
Re: rotation
Reply #2 - Jan 20th, 2006, 4:46pm
 
I just reread your post(sorry I'm groggy), you can keep the triangle where it was and have it rotate around itself as well.
Code:

float x, y;
void setup()
{
size(200, 200);
noStroke();
x = width/5.0;
y = height/5.0;
framerate(30.0);
smooth();
}

void draw()
{
background(51);
translate(x, y);
rotate(radians(mouseX)); //multiply mouseX to increase rots
stroke(255, 0, 0);
curve(500, 200, 0, 0, 300, 300, 500, 200);
beginShape(POLYGON);
vertex(35, -15);
vertex(-15, 15);
vertex(-35, -5);
endShape();
}
Page Index Toggle Pages: 1