float eSize,eSize_1,eSize_2; //オブジェクトのサイズ float speedy = 6; //オブジェクトのスピード float speedx = 2; //オブジェクトのスピード float speedy_1 = 6; //オブジェクトのスピード float speedx_1 = 8; //オブジェクトのスピード float speedy_2 = 10; //オブジェクトのスピード float speedx_2 = 4; //オブジェクトのスピード float y = 0; //オブジェクトのy座標 float x = 0; //オブジェクトのx座標 float y_1, y_2; float x_1, x_2; float c, v = 0; void setup() { size(400, 400); noStroke(); //輪郭を描かない fill(0); //オブジェクトは黒 y_1 = 200; x_1 = 200; y_2 = 200; x_2 = 200; } void draw() { background(255); /* 軌跡を残す場合は、下の3行をON、backgoundをOFFにする fill(255, 50); //透明度のあるrectを描画 rect(0, 0, width, height); fill(0); //オブジェクトは黒 */ y += speedy; x += speedx; eSize = height/3-y/3; eSize_1 = height/3-y_1/3; eSize_2 = height/3-y_2/3; ellipse(x, y, eSize, eSize); //円を描く ellipse(x_1, y_1, eSize_1, eSize_1); ellipse(x_2, y_2, eSize_2, eSize_2); //もし、yの値が画面の幅以上または0になったら、反射させる if (y>= width-10 || y <= 0) { speedy =- speedy; c += 1; } if (x>= width-10 || x <= 0) { speedx =- speedx; } //もし、xの値が画面の幅以上または0になったら、反射させる if (y_1>= width-10 || y_1 <= 10) { speedy_1 =- speedy_1; v += 1; } if (x_1>= width-10 || x_1 <= 10) { speedx_1 =- speedx_1; } //もし、xの値が画面の幅以上または0になったら、反射させる if (y_2>= width-10 || y_2 <= 10) { speedy_2 =- speedy_2; } if (x_2>= width-10 || x_2 <= 10) { speedx_2 =- speedx_2; } if (c < 5) { y_1 = y_1; x_1 = x_1; } else if (c>=5) { y_1 += speedy_1; x_1 += speedx_1; } if (c>=10) { c = 0; } if (v < 5) { y_2 = y_2; x_2 = x_2; } else if (v>=5) { y_2 += speedy_2; x_2 += speedx_2; } else if (v>=10) { v = 0; } }