float eSize = 40.0; //オブジェクトのサイズ float speedx = 7.5; //xのスピード float speedy = 3.0; //yのスピード float speedx_1 = 3.5; //xのスピード float speedy_1 = 2.0; //yのスピード float x, y, x_1, y_1= 0.0; float sp = 100; //マウスからの範囲距離 void setup() { size(400, 400); noStroke(); fill(0); } void draw() { background(255); /* 軌跡を残す場合は、下の3行をON、backgoundをOFFにする fill(255, 50); //透明度のあるrectを描画 rect(0, 0, width, height); fill(0); //オブジェクトは黒 */ x += speedx; if (x > width || x < 0)speedx =- speedx; y += speedy; if (y > height) y = 0; if (mouseX+sp >= x && mouseX -sp <= x && mouseY+sp >= y && mouseY-sp <= y) { //マウスからsp分足し引きした距離を範囲になる speedy = 10.0; noFill(); //円の色を消す } else { speedy= 3.0; fill(0); } ellipse(x, y, eSize, eSize); //円を描く x_1 += speedx_1; if (x_1 > width || x_1 < 0)speedx_1 =- speedx_1; y_1 += speedy_1; if (y_1 > height) y_1 = 0; if (mouseX+sp >= x_1 && mouseX -sp <= x_1 && mouseY+sp >= y_1 && mouseY-sp <= y_1) { //マウスからsp分足し引きした距離を範囲になる speedy_1 = 10.0; noFill(); //円の色を消す } else { speedy_1= 2.0; fill(0); } ellipse(x_1, y_1, eSize, eSize); //円を描く }