2020年10月12日 星期一

week05

 讀圖檔和座標

PImage img;
float x=100,y=200;
void setup(){
   size(500,500);
  img= loadImage("fruit.png"); 
}
void draw(){
  image(img,x,y,100,100);
}
  

水果會跳,做出白刀切水果


PImage img;
float x=100,y=200,vx=3,vy=-30;
int fruitDie=0;
void setup(){
   size(500,500);
  img= loadImage("fruit.png"); 
}
void draw(){
  background(0);//black background
  image(img,x,y,100,100);
  x+=vx;
  y+=vy;
  vy+=0.98;
  if(y>500)fruitDie=1;
  if(X<mouseX && mouseX<x+100 && y<mouseY && mouseY<y+100)fruitDie=1;//cut fruit
  stroke(255);line(mouseX,mouseY,pmouseX,pmouseY);//white knife
  if(fruitDie==1){
      if(frameCount%2==0){
        x=random(250);y=500;vx=random(2,3);vy-=random(28,32);
      }
      else {
         x=random(250,500);y=500;vx-=random(2,3);vy=-random(28,32);
      }
      fruitDie=0;
  }   
}
         先灌sound資料庫,然後撥聲音
import processing.sound.*;
SoundFile sound1;
SoundFile sound2;
void setup(){
    size(300,300);
    sound1 =new SoundFile(this, "cough.wav");
    sound2 =new SoundFile(this, "H1.wav");
    
}
void draw(){
  
}
void mousePressed(){
  sound1.play();
}

沒有留言:

張貼留言