Fun with sine and cosine

Nikolaus Gradwohl2008-10-24T06:22:00+02:00

I just played a bit with sine and cosine and got a very nice picture. the code takes some time to run, so i post a pregenerated image this time.

<typo:lightbox src="/img/guru/sincosfun.png" thumbsrc="/img/guru/sincosfun_prev.png"/>

float r;
void setup() {
  size(600,600);
  smooth();
  r = max( width/2, height/2) * 0.8;
  noLoop();
}
void draw() {
  background(0);
  stroke( 255, 2 );
  strokeWeight(2);
  lines( 4 );
  filter( BLUR, 4 );
  stroke( 255, 6 );
  strokeWeight(1);
  lines( 2);
}

void lines( float factor ) {
  for ( int j = 0; j < 360 * 10 * factor; j++ ) {
    float i = j/factor;
    line( width/2 - r * cos( radians( i / 2.1 )), 
          height/2 - r * sin( radians( i  )),
          width/2 - r * sin( radians ( i / 1.01  )),
          height/2 - r * cos( radians( 180 - i ))
    );
  }
}
read more ...