マウスオーバーで動きを変える
float t1x = 200, t1y = 100, t1r = 30, t1Vx = 0, t1Vy = 1; float t2x = 200, t2y = 315, t2w = 180, t2h = 10, t2Vx = 1, t2Vy = 1; void setup() { size(400, 400); } void draw() { background(255); t1x += t1Vx; float d = dist(mouseX, mouseY, t1x, t1y); if(d < t1r/2){ fill(255,0,0); } else { fill(0,0,255); } ellipse(t1x, t1y, t1r, t1r); t2y+=t2Vy; if (t2y < 300) { t2Vy = - t2Vy; } else if (t2y > 330) { t2Vy = - t2Vy; } if ((mouseX+t2w) >= t2x && mouseX <= (t2x+t2w)) { if ((mouseY+t2h) >= t2y && mouseY <= (t2y+t2h)) { t1Vx = 1; //別の図形を動かすことも出来る } } rect(t2x, t2y, t2w, t2h); //図形を追加していく }
Copy