Is there a way to draw a polygon of n points with a forloop by drawing lines and not using vertex()

I need to create a polygon on 9 points, the only way ive figured out how to do this is by using the beginShape , vertex(x,y) and endShape. I havent been taught these functions in class so i dont want to use them to create this polygon. is there a way to do this with just a forloop and lines?

code i have so far

int points = 9;

float centerX,centerY;

float radius = 100;

void setup(){

size(500,500);

centerX = width/2; centerY = height/2;

} void draw(){

background(200);

float angle = TWO_PI / points;

for( int i = 0 ; i < points ; i ++ ){

float posX = centerX + cos(i*angle) * radius;

float posY = centerY + sin(i*angle) * radius;

}

}

Tagged:

Answers

Sign In or Register to comment.