WEEK05
上傳圖片
PImage img;
float x=100, y=100, vx=3 ,vy=-30;
void setup(){
size(500,500);
img = loadImage("fruit.png");
}
void draw(){
image(img, x, y, 175, 215);
}
float x=100, y=100, vx=3 ,vy=-30;
void setup(){
size(500,500);
img = loadImage("fruit.png");
}
void draw(){
image(img, x, y, 175, 215);
}
(X,Y)座標
PImage img;
float x=100, y=100, vx=3 ,vy=4;
void setup(){
size(500,500);
img = loadImage("fruit.png");
}
void draw(){
image(img, x, y, 100, 100);
x += vx;
y += vy;
vy += 0.98;
}
拋物線
\PImage img;
float x=100, y=500, vx=3 ,vy=-30;
void setup(){
size(500,500);
img = loadImage("fruit.png");
}
void draw(){
image(img, x, y, 100, 100);
x += vx;
y += vy;
vy += 0.98;
if(y>500){
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);
}
}
}
切水果
PImage img;
float x=100, y=500, vx=3 ,vy=-30;
int fruitDie=0;
void setup(){
size(500,500);
img = loadImage("fruit.png");
}
void draw(){
background(0);
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;
stroke(255);line(mouseX,mouseY,pmouseX,pmouseY);
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;
}
}
加入聲音
import processing.sound.*;
SoundFile sound1;
SoundFile sound2;
void setup(){
size(300,300);
sound1 = new SoundFile(this, "sound1.wa");
sound2 = new SoundFile(this, "sound2.wav");
//sound1.play();
sound2.loop();
}
void draw(){
}
void mousePressed(){
sound1.play();
}




沒有留言:
張貼留言