1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| float y1; float y2; float y3; float y4; float y5; float t1; float t2; float t3; float t4; float t5; void setup() { size(500, 500); } void draw() { background(0); Draw_Button(); } void Draw_Button() { { t1 ++; t2 ++; t3 ++; t4 ++; t5 ++; t1 = constrain(t1, 0, 60); t2 = constrain(t2, 0, 60); t3 = constrain(t3, 0, 60); t4 = constrain(t4, 0, 60); t5 = constrain(t5, 0, 60); y1 = easeInOut_Expo(t1, 0, 400, 60); y2 = easeInOut_Expo(t2, 0, 400, 60); y3 = easeInOut_Expo(t3, 0, 400, 60); y4 = easeInOut_Expo(t4, 0, 400, 60); y5 = easeInOut_Expo(t5, 0, 400, 60); } pushMatrix(); translate(0, y1); rect(width/5*0, 0, 100, 100); popMatrix(); pushMatrix(); translate(0, y2); rect(width/5*1, 0, 100, 100); popMatrix(); pushMatrix(); translate(0, y3); rect(width/5*2, 0, 100, 100); popMatrix(); pushMatrix(); translate(0, y4); rect(width/5*3, 0, 100, 100); popMatrix(); pushMatrix(); translate(0, y5); rect(width/5*4, 0, 100, 100); popMatrix(); } void mousePressed() { if (overRect(width/5*0, 0, 100, 500)) { t1 = 0; } else if (overRect(width/5*1, 0, 100, 500)) { t2 = 0; } else if (overRect(width/5*2, 0, 100, 500)) { t3 = 0; } else if (overRect(width/5*3, 0, 100, 500)) { t4 = 0; } else if (overRect(width/5*4, 0, 100, 500)) { t5 = 0; } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } float easeInOut_Expo(float t, float b, float c, float d) { if (t==0) return b; if (t==d) return b+c; if ((t/=d/2) < 1) return c/2 * pow(2, 10 * (t - 1)) + b; return c/2 * (-pow(2, -10 * --t) + 2) + b; }
|