2018年10月3日 星期三

Week03劉峻宇

                                           課堂學習


1.老師先教我們可以用processing畫出一個幾何圖形的圓
用這程式碼 新學的
}
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));
     }
   }
}

可以自己取想要畫的圓周


2.
以下程式碼可以畫出很多幾何三角形
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);
    }
  }
}




3.
用一個程式碼來畫馬力歐

先把馬力歐圖片匯入資料夾

再用此程式碼
void setup(){
  size(400,600);
}
void draw(){
  background(255);
  
  PImage imgMario = loadImage("mario.png");
  image(imgMario, 0,0, 200,150);
}




4.
接下來我們要讓馬力歐能夠跳躍
我們只要加上這幾個程式碼就可以囉

PImage imgMario;
float marioX=0, marioY=100, marioVX=5, marioVY=0, marioAX, marioAY=0.1;
void setup(){
  size(400,600);
  imgMario = loadImage("mario.png");
}
void draw(){
  background(255);
  image(imgMario, marioX,marioY, 200,150);
  marioX += marioVX;  marioY += marioVY;
  marioVX+= marioAX;  marioVY+= 0.98; 
  if(marioY>600-150) marioVY*=-0.9;
  if(marioX>400-100) marioVX*=-1;
  if(marioY<0) marioVY*=-0.9;
  if(marioX<0) marioVX*=-1;
}







沒有留言:

張貼留言