Polygon

|
사용법 : 키보드의 방향키 상하키를 누르면 꼭지점이 줄어들고 늘어난다.
좌우키를 누르면 크기가 변한다.

문제점 : 다각형의 꼭지점이 늘어날때마다 각을 새로 계산해서 평균각을 구하여 도형이 생성되야하는데...
int width = 320;
int height = 240;
int shapePoint = 1;

int loc = 50;

void setup(){
size(width, height);

smooth();
background(0);
}

void draw(){

background(0);


beginShape();
translate(width/2, height/2);
for(int i = 0; i < 360; i+= shapePoint){
float sinX = sin(radians(i)) * loc;
float cosY = cos(radians(i)) * loc;
vertex(sinX, cosY);
}
endShape(CLOSE);
println(shapePoint);

}

void keyPressed(){
if(keyCode == UP){
shapePoint ++;
if(shapePoint > 120) shapePoint = 120;
}
if(keyCode == DOWN){
shapePoint --;
if(shapePoint < 1) shapePoint = 1;
}
if(keyCode == LEFT){
loc --;
}
if(keyCode == RIGHT){
loc ++;
}

}
And