【Processing】tan()を使う



94.hatenadiary.jp

この記事の続き。


sin()とcos()はよく使うけど、tan()はいつ使うかな〜と思って書いてみた。
回転しながら描画する際に、彩度にtan()をあてるとこんな感じになった。
手応えは普通。


float degree; //角度
int[] a = new int[9];

void setup() {
  size(800, 800);
  background(0);
  frameRate(200);
  blendMode(ADD);
  colorMode(HSB, 360, 100, 100, 100);
  degree = 0;
  for (int i = 0; i < 9; i++) {
    a[i] = ((4*(int)random(i+1)) )+ 1; //絶対奇数の整数にする
    println(a[i]);
  }
}


void draw() {

  translate(width/2, height/2); //座標を中心に移動

  float x = (20*a[0])* cos(radians(degree*a[1])); 
  float y = (20*a[0])* sin(radians(degree*a[1])); 
  float _x = x + (40*a[2])* cos(radians(degree*a[3])); 
  float _y = y + (40*a[2])* sin(radians(degree*a[3])); 
  float __x = _x + (40*a[4])* cos(radians(degree*a[5])); 
  float __y = _y + (40*a[4])* sin(radians(degree*a[5])); 
  float ___x = __x + (40*a[6])* cos(radians(degree*a[7])); 
  float ___y = __x + (40*a[6])* sin(radians(degree*a[7])); 

  strokeWeight(1);
  //彩度の計算にタンジェントをつかうよ〜〜〜〜
  stroke(degree, 100*tan(radians(degree*a[8])), 80, 5) ;
  line(x, y, _x, _y);
  line(_x, _y, __x, __y);
  line(__x, __y, ___x, ___y);
  degree+=0.05; //角度を足す
  //println(degree);

  //一周したらストップ
  if (degree > 360) {  
    save("save/save.jpg");
    stop();
  }
}