- 処理を繰り返す
- 繰り返しを繰り返す
- ランダムに決める
for 処理を繰り返す
(この条件) を満たす間は繰り返し {この処理の実行する}
size(400,200);
int x=100;
int y=100;
int d=60;
for(int i=1; i<=3; i++){
ellipse(x+100*i,y,d,d);
}
※前回の授業では以下のように書いていた。 その1
size(400,200);
int x=100;
int y=100;
int d=60;
ellipse(x,y,d,d);
x+=100;
ellipse(x,y,d,d);
x+=100;
ellipse(x,y,d,d);
※前回の授業では以下のように書いていた。 その2
size(400,200);
ellipse(100,100,60,60);
ellipse(200,100,60,60);
ellipse(300,100,60,60);
練習
- 円を5つ並べてみる
- 一定の大きさで小さくなる円を3つ描く
繰り返しを繰り返す
size(200,200);
colorMode(HSB,100);
background(99);
noStroke();
for(int x=0; x<10; x++){
fill(x*10,10,99);
rect(x*20,0,10,10);
}
for文の中にfor文を書くことができる
size(200,200);
colorMode(HSB,100);
background(99);
noStroke();
for(int y=0; y<10; y++){
for(int x=0; x<10; x++){
fill(10*x,10+y*10,99);
rect(x*20,y*20,10,10);
}
}
random ランダムに決める
size(200,200);
colorMode(RGB,100);
background(99);
for(int i=0; i<100; i++){
stroke(0);
line(random(width),random(height),random(width),random(height));
}
※プログラムが実行されるたびに、出力結果が変わる。
色もランダムにしてみる
size(200,200);
colorMode(RGB,100);
background(99);
for(int i=0; i<100; i++){
stroke(random(100),random(100),random(100));
line(random(width),random(height),random(width),random(height));
}
ランダムな値(乱数)を変数に入れて利用する
size(200,200);
colorMode(HSB,100);
background(99);
for(int x=0; x<width; x++){
float color1 = random(100); // 色を設定する乱数の値は0から100未満とする
stroke(color1,60,99);
line(x,0,x,height);
}
※randomはfloat型で変数を設定する(int型にするとエラーになる)。
- Newer: 1a-06 条件と分岐
- Older: 1a-04 計算と変数










![Built with Processing [改訂版]](http://ecx.images-amazon.com/images/I/41XEE%2BuMOzL._SL160_.jpg)




