I have just started to play around with processing. I was trying to write a code which draws a polygon for each mouse click. but with each click the sides the polygon changes from n-sides polygon to (n+1)sides polygon
so when you click for the first time, a triangle is drawn, for the second click, a square and so forth.
i have tried doing it by finding the vertices of the polygons using polar coordinates(which i have made to lie on a circle of radius 40) and then joining the vertices.
it works fine only till the nonagon(nine sided polygon). after that it gives an incomplete polygon(with 1 side missing!)
can anyone tell me why is this happening?
here is the code,
int x=3;
void setup() //basics
{
size(800,800);
background(255);
stroke(30,180,30);
}
void draw()
{
}
void mouseClicked()
{
float a=0,b=0;
int r=40; //creating a circle
while(b<=TWO_PI) // calculating b till it becomes 360
{
point (mouseX,mouseY);
line(mouseX+r*cos(a),mouseY+r*sin(a),mouseX+r*cos(b),mouseY+r*sin(b)); //drawing line between a and b