2014年9月29日 星期一

第三周課堂作業


讀取網路上的影像檔
size(800,600);
PImage img = loadImage("http://metrouk2.files.wordpress.com/2014/03/sherlock-benedict-martin.jpg");
image(img, 0,0, 700,450);

讀取圖片(隨滑鼠移動)
PImage img;
void setup(){
size(800,600);
img = loadImage("bus.png");
imageMode(CENTER);
}
void draw(){
  background(0,255,0);
  image(img, mouseX,mouseY, 300,300);
}

加上背景 還有白球
PImage img, imgBG;
float eggX=750, eggY=550, eggVX, eggVY, flying=0;
void setup() {
  size(800, 600);
  img = loadImage("bus.png");
  imgBG = loadImage("bg.png");
  imgBG.resize(800, 600);
  imageMode(CENTER);
}
void draw() {
  background(imgBG);
  image(img, mouseX, mouseY, 300, 300);
  if (flying>0) {
    ellipse(eggX, eggY, 50, 50);
    eggX+= eggVX;
    eggY+= eggVY;
    flying--;
  }
}
void mousePressed() {
  eggX=750; 
  eggY=550; 
  flying=30;
  eggVX= (mouseX-eggX)/30;
  eggVY= (mouseY-eggY)/30;
}
加上音效 喇叭聲
import ddf.minim.*;
Minim minim;
AudioPlayer brake2;
PImage img, imgBG;
float eggX=750, eggY=550, eggVX, eggVY, flying=0;
void setup() 
{
  size(800, 600);
  minim = new Minim(this);
  img = loadImage("bus.png");
  imgBG = loadImage("bg.png");
  imgBG.resize(800, 600);
  imageMode(CENTER);
  brake2 = minim.loadFile("carhn.wav");

}
void draw() {
  background(imgBG);
  image(img, mouseX, mouseY, 300, 300);
  if (flying>0) {
    ellipse(eggX, eggY, 50, 50);
    eggX+= eggVX;
    eggY+= eggVY;
    flying--;
  }
}
void mousePressed() {
  eggX=750; 
  eggY=550; 
  flying=30;
  eggVX= (mouseX-eggX)/30;
  eggVY= (mouseY-eggY)/30;
  
  brake2.rewind();
  brake2.play();
}



沒有留言:

張貼留言