教科書 p.66〜p.71
- 正方形を画面にちりばめる
正方形を画面にちりばめる
size(400,400);
colorMode(HSB,100);
background(99);
smooth();
noStroke();
int d=20; //正方形の一辺の長さ
for(int i=0; i<300; i++){
pushMatrix(); //座標をセーブ
fill(random(0,20),99,99,50); //色の設定
translate(random(width),random(height)); //座標をランダムに移動
rotate(radians(random(360))); //座標をランダムに回転
rect(0,0,d,d); //正方形を描く
popMatrix(); //座標をロードし、座標を(0,0)に戻す
}
rotate文のみで表現することもできる。この場合、画面からはみ出たところに描画される部分を考慮し、for文での繰り返しの数を4倍に設定しておく。
size(400,400);
colorMode(HSB,100);
background(99);
smooth();
noStroke();
int d=20;
for(int i=0; i<1200; i++){
fill(random(0,20),99,99,50);
rotate(radians(random(360)));
rect(random(width),random(height),d,d);
}

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




