2020年10月5日 星期一

week4

 將圖檔用Processing顯示

先將圖檔拖入Processing視窗

再輸入

PImage img;

size(1200,628);

img = loadImage("image.jpg");

image( img, 0, 0);

 

使第二章圖片隨鼠標移動
PImage img;
PImage img2;
void setup(){
  size(1200,628);
  img = loadImage("image2.jpg");
  img2 = loadImage("image.jpg");
}
void draw(){
  image( img, 0, 0);
  image( img2,mouseX-54/2,mouseY-49/2,54,49);
}


做圖片卷軸橫向移動
PImage img;
PImage img2;
void setup(){
  size(1200,628);
  img = loadImage("image3.jpg");
  img2 = loadImage("image.jpg");
}
int x=0;
void draw(){
  if(mouseX>1100)x--;
  image( img, x, 0);
  image( img2,mouseX-54/2,mouseY-49/2,50,50);
}


做一個碰到邊界球會反彈的程式
float x=250,y=200;
float vx=1.0,vy=2.5;
void setup(){
  size(500,400);
}
void draw(){
  ellipse(x,y,10,10);
  x+=vx;
  y+=vy;
  if(x>500 || x<0) vx = -vx;
  if(y>400 || y<0) vy = -vy;
}


做球掉落後彈起的程式
float x=250,y=200;
float vx=1.3,vy=-14;
void setup(){
  size(500,400);
}
void draw(){
  ellipse(x,y,10,10);
  x+=vx;
  y+=vy;
  vy += 0.98;
  if(x>500 || x<0) vx = -vx*0.85;
  if(y>400 || y<0) vy = -vy*0.85;
}




沒有留言:

張貼留言