六角形
運用三角函數寫程式
void setup(){
size(500,500);
}
void draw(){
ellipse(250,250,480,480);
for(float angle=0;angle<PI*2;angle+=PI/3){
triangle(250,250,
250+240*cos(angle),250+240*sin(angle),
250+240*cos(angle+PI/3),250+240*sin(angle+PI/3));
}
}
void setup(){
size(500,500);
}
void draw(){
ellipse(250,250,480,480);
for(float angle=0;angle<PI*2;angle+=PI/3){
for(int R=0;R<=240;R+=20){
noFill();
triangle(250,250,
250+R*cos(angle),250+R*sin(angle),
250+R*cos(angle+PI/3),250+R*sin(angle+PI/3));
}
}
}
三角形
void setup(){
size(800,400);
}
void myTriangle(int cx,int cy){
float a=-PI/2;
for(int R=15;R>0;R-=5){
triangle(cx+R*cos(a),cy+R*sin(a),
cx+R*cos(a+2*PI/3),cy+R*sin(a+2*PI/3),
cx+R*cos(a-2*PI/3),cy+R*sin(a-2*PI/3));
}
}
void draw(){
background(255);
for(int cx=20;cx<800;cx+=40){
for(int cy=20;cy<400;cy+=40){
myTriangle(cx,cy);
}
}
}
瑪莉歐
PImage imgMario;
float marioX=0, marioY=0;
void setup(){
size(400,600);
imgMario=loadImage("mario.png");
}
void draw(){
background(255);
image(imgMario,marioX,marioY,100,150);
}
void keyPressed(){
if(keyCode==UP) {marioY-=5;}
if(keyCode==DOWN) {marioY+=5;}
if(keyCode==LEFT) {marioX-=5;}
if(keyCode==RIGHT) {marioX+=5;}
}
PImage imgMario;
float marioX=0,marioY=0,marioVX=2,marioVY=0,marioAX=0,marioAY=0.1;
void setup(){
size(400,600);
imgMario=loadImage("mario.png");
}
void draw(){
image(imgMario,marioX,marioY,100,150);
marioX+=marioVX; marioY+=marioVY;
marioVX+=marioAX; marioVY+=marioAY;
}
void keyPressed(){
if(keyCode==UP) {marioY-=5;}
if(keyCode==DOWN) {marioY+=5;}
if(keyCode==LEFT) {marioX-=5;}
if(keyCode==RIGHT) {marioX+=5;}
}
當掉或是跑不出檔案:可能是檔案名稱打錯
PImage imgMario;
float marioX=0,marioY=0,marioVX=2,marioVY=0,marioAX=0,marioAY=0.1;
void setup(){
size(400,600);
imgMario=loadImage("mario.png");
}
void draw(){
image(imgMario,marioX,marioY,100,150);
marioX+=marioVX; marioVX+=0;
marioY+=marioVY; marioVY+=0.98;
if(marioY>500){
marioVY=-marioVY*0.8;
marioY=500;
}
if(marioX>500) marioVX=-marioVX;
if(marioX<0) marioVX=-marioVX;
}
void keyPressed(){
if(keyCode==UP) {marioY-=5;}
if(keyCode==DOWN) {marioY+=5;}
if(keyCode==LEFT) {marioX-=5;}
if(keyCode==RIGHT) {marioX+=5;}
}
沒有留言:
張貼留言