Home > 1a > | ノート > 1a-12 座標を変換する

1a-12 座標を変換する

  • Posted by: masa
  • 2009年7月 6日 14:40
  • 1a | ノート

教科書 p.66〜p.71

  • 正方形を画面にちりばめる

正方形を画面にちりばめる

translate-rotate-random

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);
}

関連エントリー

Home > 1a > | ノート > 1a-12 座標を変換する

Search
Feeds
Textbook
  • Built with Processing [改訂版]
Recommends
  • Processing – A Programming Handbook for Visual Designers and Artists
  • Learning Processing: A Beginner's Guide to Programming Images, Animation, and Interaction (Morgan Kaufmann Series in Computer Graphics)
  • Arduinoをはじめよう
  • ビジュアライジング・データ ―Processingによる情報視覚化手法
  • +GAINER―PHYSICAL COMPUTING WITH GAINER

Return to page top