2020年10月28日 星期三

🗿Week07 (期中作業)



畫出圓



size(500,500);
for(int angle=0;angle<360;angle+=30){
  float angle2 = radians(angle); ///弧度
  float x = 100+cos(angle2)*50;
  float y = 100+sin(angle2)*50;
  ellipse(x,y,2,2); //劃出點 大小(2,2)
} 



利用三角函數畫三角形


程式碼:
size(500,500);
beginShape();
for(int angle=0;angle<360;angle+=120){ ///加120度為三角形
  float angle2 = radians(angle);
  float x = 100+cos(angle2)*50;
  float y = 100+sin(angle2)*50;
  vertex(x,y); ///點
}
endShape(CLOSE);


滑鼠旋轉游標,三角形跟著轉


程式碼:
void setup(){
  size(500,500);
}
void draw(){
  //background(255);//清畫面
  beginShape();
  for(int angle=0;angle<360;angle+=120){
    float angle2 = radians(angle+mouseX);
    float x = 100+cos(angle2)*50;
    float y = 100+sin(angle2)*50;
    vertex(x,y);
  }
  endShape(CLOSE);
}


三角形跟著滑鼠移動


程式碼:
void setup(){
  size(500,500);
}
void draw(){
  ///background(255);//清畫面
  beginShape();
  for(int angle=0;angle<360;angle+=120){
    float angle2 = radians(angle+mouseX);
    float x = mouseX+cos(angle2)*50;
    float y = mouseY+sin(angle2)*50;
    vertex(x,y);
  }
  endShape(CLOSE);
}


三角形自己旋轉,滑鼠可以移動它


*1sec = 60frame
程式碼:
void setup(){
  size(500,500);
}
void draw(){
  ///background(255);//清畫面
  beginShape();
  for(int angle=0;angle<360;angle+=120){
    float angle2 = radians(angle+frameCount); ///frameCount=螢幕每秒會跑60次
    float x = mouseX+cos(angle2)*100;
    float y = mouseY+sin(angle2)*100;
    vertex(x,y);
  }
  endShape(CLOSE);
}


接水果遊戲


程式碼:
float [] fruitX=new float[10];
float [] fruitY=new float[10];
float kidX=150,kidY=450;
int score=0;
void setup(){
  size(500,500);
  for(int i=0;i<10;i++){
    fruitX[i] = random(50,450);
    fruitY[i] = -i*100;
   }
}
void draw(){
  background(255);
  rect(kidX,kidY,80,80);
  kidX=mouseX;
  for(int i=0;i<10;i++){
    ellipse(fruitX[i],fruitY[i],60,80);
    fruitY[i]++;
    if(fruitY[i]>kidY){///水果掉夠低
      if(kidX<fruitX[i] && fruitX[i]<kidX+80){///接到水果
        score+=10;///接住了就加分
        fruitY[i]=0;  fruitX[i]=random(50,450);///水果重生
      }else{
        fruitY[i]=0; fruitX[i]=random(50,450);///沒接住,水果重生
      }
    }
  }
}

_______________________________________________________________________

PImage pic;
PImage car;
PImage bg;
PImage die;
float [] picX=new float[10];
float [] picY=new float[10];
float carX=150, carY=450;
int score=0;

void setup() {
  size(513, 615);
  for (int i=0; i<10; i++) {
    picX[i] = random(70, 295);
    picY[i] = -i*100;
    picY[i]--;
  }
  pic = loadImage("pic.png");///三角椎
  car = loadImage("car.png");
  bg = loadImage("bg.png");
  die =loadImage("die.png");
}

void draw() {
  image(bg, 0, 0, 513, 615);
  //background(255);
  image(car, carX, carY, 100, 100);
  carX=mouseX;

  for (int i=0; i<7; i++) {
    image(pic, picX[i], picY[i], 150, 170);
    picY[i]+=1;
    /*if(picY[i]>carY){///三角錐掉夠低
     if(carX<picX[i] && picX[i]<carX+80){///接到三角錐
     score+=10;///接住了就扣分
     picY[i]=0;  picX[i]=random(70,455);///三角錐重生
     }else{
     picY[i]=0; picX[i]=random(70,455);///沒接住,三角錐重生
     }
     }
     */
    if (picY[i]>615)
    {
      picY[i]=-183;  
      picX[i]=random(70, 295);///三角錐重生
    }
    if (picY[i]>carY) {
      if (carX<picX[i] && picX[i]<carX+100) {///車碰到三角錐
        image(die, 0, 0, 513, 615);
      }
    }
  }
}














PImage pic;
PImage car;
PImage bg;
PImage die;
PImage heart;
float [] picX=new float[10];
float [] picY=new float[10];
float carX=150, carY=450;
int score=50;
int h=0;

void setup() {

  size(513, 615);
  for (int i=0; i<10; i++) {
    picX[i] = random(70, 295);
    picY[i] = -i*100;
  }
  pic = loadImage("pic.png");///三角椎
  car = loadImage("car.png");
  bg = loadImage("bg.png");
  die =loadImage("die.png");
}

void draw() {
  if (h==0) {
    image(bg, 0, 0, 513, 615);
    //background(255);
    carX=mouseX-47;
    image(car, carX, carY, 50, 100);



    for (int i=0; i<7; i++) {
      image(pic, picX[i], picY[i], 60, 60);
      picY[i]+=2;
      if (picY[i]>615)
      {
        picY[i]=-183;  
        picX[i]=random(70, 295);///三角錐重生
      }
      if (picY[i]+60>carY) {
        if (carX<picX[i]+58 && picX[i]<carX+48) //2cm
        {///車碰到三角錐
          score-=10;
         picY[i]=-150;
        }
      }
    }
    textSize(50);
    text(score,50, 100);
  }
  if (score==0)
  {
    h=1;
    image(die, -35, 100, 600, 350);
  }
}
void keyPressed() {
  if (keyCode == ENTER)
  {
    h=0;
    score=50;
  }
}

______________________________________________

沒有留言:

張貼留言