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 › Rotate->Vertex->Rotate->Vertex...
Page Index Toggle Pages: 1
Rotate->Vertex->Rotate->Vertex... (Read 684 times)
Rotate->Vertex->Rotate->Vertex...
Mar 16th, 2007, 12:35am
 
Can someone give me a hand with my first program.

I'm trying to make an N-Gon but something seems to be failing.

int winSize = 500;

void setup()
{
 size(winSize, winSize);
 stroke(102);
 smooth();
 frameRate(30);
}

void draw()
{
background(0);
stroke(127);
fill(77);
float numSides = 6.0;

translate(100,100);

 beginShape();
 for(int i = 0; i<numSides; i++)
 {
   rotate((i / numSides) * 6.28318);
   vertex(0, 10);
 }
 endShape();  
}
Re: Rotate->Vertex->Rotate->Vertex...
Reply #1 - Mar 16th, 2007, 8:22am
 
As all points of your ngon lie on a circle, you have to create points with the same angle on a circle. So you have divide TWO_PI (thats 360 degree) by your sideNum and multiply by your i in the for-loop.

Quote:


int winSize = 500;

void setup()  
{
 size(winSize, winSize);
 smooth();
 stroke(127);
 fill(77);
}

void draw()  
{
 background(250);

 int numSides = 4;
 float rad=100; //the radius of your ngon
 translate(100,100);

 beginShape();
 for(int i = 0; i<numSides; i++)
 {
   float x=cos(TWO_PI/numSides*i)*rad;
   float y=sin(TWO_PI/numSides*i)*rad;
   vertex(x, y);
 }
 endShape();
}


Page Index Toggle Pages: 1