2018年10月4日 星期四

week04






開始畫面:
程式碼:

void setup(){
size(800,600);
}

void draw(){
  fill(250,0,0);
 
  ellipse(200,80,200,100);
  textSize(80);
  fill(0,0,0);
  text("Start!!",100,100);
}





2.




按下空白鍵讓子但連續發射
程式碼:
void setup(){
  size(800,600);
}

void draw(){
  background(255);
   fill(255,0,0); rect(100,100,100,100);
   for(int i=0; i<bulletN; i++){
     if(bulletFlying[i]){
       ellipse(bulletX[i],bulletY[i],50,50);
       bulletX[i]+=3;
     }
   }
}
float[]bulletX= new float[100];
float[]bulletY= new float[100];
int bulletN=0;
boolean []bulletFlying= new boolean[100];

void keyPressed(){
  bulletFlying[bulletN] = true;
  bulletX[bulletN] = 100;  bulletY[bulletN] = 100;
  bulletN++;
}






3.





程式碼:
PImage imgflower, imgBG;

void setup() {
  size(800,600);
  imgBG = loadImage("BG.jpg.jpg");
  imgflower = loadImage("flower.png.jpg");
  imageMode(CENTER);
}

void draw() {
  image(imgBG, width/2, height/2, width, height);
  image(imgflower, mouseX, mouseY, 100, 100);
  for (int i=0; i<flowerN; i++) {
    if (flowerFlying[i]) {
      image(imgflower, flowerX[i], flowerY[i], 100, 100);
     //flowerY[i]+=3;                                                                     //控制花落下的方向與速度
    }
  }
}

float[]flowerX= new float[100];
float[]flowerY= new float[100];

boolean[]flowerFlying = new boolean[100];
int flowerN=0;

void mousePressed() {
  flowerFlying[flowerN]=true;
  flowerX[flowerN]=mouseX;
  flowerY[flowerN]=mouseY;
  flowerN++;
}




去背網址:https://www.pkstep.com/archives/23856






























沒有留言:

張貼留言