ウインドウの四隅でボールがバウンドするように,以下のプログラムを完成させよ.
//ボールの初期位置 float px = 100; float py = 100; //ボールの速度 float vx = 2; float vy = 1; //ボールの直径 float r = 10; void setup() { size(200, 200); noStroke(); smooth(); fill(0, 0, 0); } void draw() { background(255, 255, 255); //ボールが四隅に接触してバウンドする処理を記述 ellipse(px, py, r, r); }
配列とfor文を使用し,問1のボールを30個にせよ.
//ボールの位置 int numball = 30; float[] px = new float[numball]; float[] py = new float[numball]; //ボールの速度 float[] vx = new float[numball]; float[] vy = new float[numball]; //ボールの直径 float r = 10; void setup() { size(200, 200); noStroke(); smooth(); fill(0, 0, 0); //ボールの位置,速度をランダムに初期化 } void draw() { background(255, 255, 255); //ボールが四隅に接触してバウンドする処理を記述 //ボールを描画 }
5つのボールの内,最大の大きさのボールを赤で描くようにせよ.
size(200, 200); background(255, 255, 255); smooth(); noStroke(); fill(0, 0, 0); //直径を初期化 float[] r = new float[5]; for(int i = 0; i < 5; i++) { r[i] = random(1,30); } //最大の直径の円が何番目かを探す float maxr = 0; int maxindex = 0; ??? //円を描く for(int i = 0; i < 5; i++) { if (i == maxindex) fill(255, 0, 0); else fill(0, 0, 0); ellipse((i+1) * 30, 100, r[i], r[i]); }
textを利用し,問3のボールの直径を表示せよ.
配列とfor文を利用し,以下のようにスクロールする波形のようなアニメーションを描画せよ.