Week07
程式作圖
*做頂點
size(500,500);
for(int a=0;a<360;a+=60){///做正多邊形
float a2=radians(a);
float x=100+cos(a2)*50;
float y=100+sin(a2)*50;
ellipse(x,y,2,2);
}
*做多邊形
size(500,500);
beginShape();
for(int a=0;a<360;a+=60){///做正多邊形
float a2=radians(a);
float x=100+cos(a2)*50;
float y=100+sin(a2)*50;
vertex(x,y);
}
fill(255,0,0);
endShape(CLOSE);
*圖形旋轉
void setup(){
size(500,500);
}
void draw(){
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+mouseX);
float x=100+cos(a2)*50;
float y=100+sin(a2)*50;
vertex(x,y);
}
fill(0,0,225);
endShape(CLOSE);
}
*圖形旋轉隨滑鼠移動
void setup(){
size(500,500);
}
void draw(){
background(255);
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+mouseX);
float x=mouseX+cos(a2)*50;
float y=mouseY+sin(a2)*50;
vertex(x,y);
}
fill(0,0,225);
endShape(CLOSE);
}
*三角形隨著每一幀轉動
void setup(){
size(500,500);
}
void draw(){
//background(255);
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+frameCount);//frameCount表示第幾個frame
float x=mouseX+cos(a2)*50;
float y=mouseY+sin(a2)*50;
vertex(x,y);
}
fill(0,0,225);
endShape(CLOSE);
}
*多邊形陣列
void setup(){
size(500,500);
}
void draw(){
int s=0;
background(255);
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+frameCount*2);//frameCount表示第幾個frame
float x=(j+1)*100+cos(a2)*35-50;
float y=(i+1)*100+sin(a2)*35-60;
vertex(x,y);
if(s%2==0){
fill(0,0,255);
s++;
}
if(s%2==1){
fill(255,0,0);
s++;
}
}
endShape(CLOSE);
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+frameCount*2);//frameCount表示第幾個frame
float x=(j+1)*100+cos(a2)*20-50;
float y=(i+1)*100+sin(a2)*20-60;
vertex(x,y);
if(s%2==0){
fill(0,0,255);
s++;
}
if(s%2==1){
fill(0,0,225);
s++;
}
}
endShape(CLOSE);
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+frameCount*2);//frameCount表示第幾個frame
float x=(j+1)*100+cos(a2)*10-50;
float y=(i+1)*100+sin(a2)*10-60;
vertex(x,y);
if(s%2==0){
fill(0,255,0);
s++;
}
if(s%2==1){
fill(0,255,0);
s++;
}
}
endShape(CLOSE);
}
}
endShape(CLOSE);
}
*多邊形陣列(2.0)
void setup(){
size(500,500);
}
void draw(){
int s=0;
background(255);
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
s++;
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a-frameCount*1);//frameCount表示第幾個frame
float x=(j+1)*50+cos(a2)*20-10;
float y=(i+1)*50+sin(a2)*20-10;
vertex(x,y);
if(s%2==0)stroke(255,0,0);
else stroke(0,0,255);
}
endShape(CLOSE);
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a+frameCount*2);//frameCount表示第幾個frame
float x=(j+1)*50+cos(a2)*15-10;
float y=(i+1)*50+sin(a2)*15-10;
vertex(x,y);
if(s%2==0)stroke(255,0,0);
else stroke(0,0,255);
}
endShape(CLOSE);
beginShape();
for(int a=0;a<360;a+=120){///做正多邊形
float a2=radians(a-frameCount*4);//frameCount表示第幾個frame
float x=(j+1)*50+cos(a2)*10-10;
float y=(i+1)*50+sin(a2)*10-10;
vertex(x,y);
if(s%2==0)stroke(255,0,0);
else stroke(0,0,255);
}
endShape(CLOSE);
}
}
}







沒有留言:
張貼留言