int eSize = 20; //オブジェクトのサイズ float velocity = 0.0; //オブジェクトのスピード float vControl = 0.2; //スピードのコントロール float maxVel = 10.0; //スピードの最大値 float x = 0.0; //オブジェクトのx座標 void setup() { size(400, 400); background(255); //背景は白 noStroke(); //輪郭を描かない fill(0); //オブジェクトを黒で塗りつぶす } void draw() { background(255); //画面の色を更新 //軌跡を残す場合は、下の3行をON、backgroundをOFFにする /* fill(255, 10); //透明度のあるrectを描画 rect(0, 0, width, height); fill(0); //オブジェクトは黒 */ ellipse(x, height/2, eSize, eSize); //円を描く //スピードが最大か0になったらvControlを反転 if (velocity > maxVel || velocity < 0.0) vControl = -vControl; x += velocity; //x座標にvelocityの値を足す velocity += vControl; if ((x > width)||( x < 0)) { //もし、xの値が画面の幅以上になったら、xを0に戻す velocity = -velocity; } }