Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float x=50 ;
- float y =0 ;
- float dx = 6 ;
- float dy = 5 ;
- float w = 150 ; //圖片寬度、高度
- PImage img; //宣告圖片物件
- //挑戰題:
- //1、將顯示動作更改成水平左右移動,邊界反彈
- //2、將顯示動作增加垂直上下移動,邊界反彈
- void setup(){
- size(1024, 800);
- //width為畫面的寬度,height為畫面的高度
- background(100,100,50) ;
- }
- int idx = 0;
- void draw() {
- if(idx %2 == 0)
- img = loadImage("dog.png"); //載入圖片
- else
- img = loadImage("d.png");
- idx++;
- background(100,100,50) ;
- image(img, x, y, w, w); //顯示圖片
- println(y, dy) ;
- y += dy; //更改位置
- if(y + w >= height)
- dy = -5;
- if(y < 0)
- dy = 5;
- x += dx; //更改位置
- /*if(x + w >= width)
- dx = -6;
- if(x < 0)
- dx = 6;*/
- dx = x+w >= width ? -6:6;
- delay(300);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement