红色箭头向左跑出屏幕,且可以切换快速和慢速
1 PImage pic, button; 2 float posx=450, posy=220; 3 float speed=-1; 4 int col; 5 void setup() { 6 size(900, 600); 7 pic = loadImage("pic1.png"); 8 button=loadImage("button.png"); 9 } 10 void draw() { 11 background(0); 12 image(pic, -15, -20); 13 rectgroud(posx, posy); 14 rectgroud(posx-300, posy); 15 rectgroud(posx+300, posy); 16 posx +=speed; 17 if (posx<-450) { 18 posx=1250; 19 } 20 textSize(24); 21 text("<<", 360, 556); 22 text("<", 444, 556); 23 stroke(155); 24 strokeWeight(2); 25 noFill(); 26 rect(340, 530, 80, 40); 27 rect(420, 530, 80, 40); 28 image(button, 525, 530, 40, 40); 29 } 30 31 void rectgroud(float x, float y) { 32 fill(210, col, 0); 33 noStroke(); 34 push(); 35 translate(x, y); 36 rotate(PI/4); 37 rect(0, -200, 100, 200); 38 rect(0, 0, 300, 100); 39 pop(); 40 } 41 42 void mousePressed() { 43 if (mouseX>340 && mouseX<420) { 44 if (mouseY>530 && mouseY<570) { 45 speed=-4; 46 } 47 } 48 if (mouseX>420 && mouseX<500) { 49 if (mouseY>530 && mouseY<570) { 50 speed=-2; 51 } 52 } 53 if (dist(mouseX, mouseX, 545, 550)<20) { 54 col=250; 55 } 56 } 57 void mouseReleased() { 58 speed=-1; 59 col=0; 60 }