From Processing to Gif Series 0

2016-01-02  本文已影响0人  Tealeaf
Trying To Break Free By Jerome Herr

I went on checking this generous and gifted author's openProcessing page, trying to dig out more about his talents of creating digital loop motion. Then this piece of work enlightened my eyes.

Code:

int sz = 400, num=20;
float theta, angle, rad = 60;
 
void setup() {
  size(500, 500);
  fill(0);
  stroke(255);
  strokeWeight(8);
}
 
void draw() {
  background(255);
  angle=0;
  for (int i=0; i<num; i++) {
    float x = width/2-rad/2 + cos(angle)*rad;
    float y = height/2 + sin(angle)*rad;
    float s = map(sin(theta+TWO_PI/num*i),-1,1,1,.6);
    float scal = 1-0.045*i;
    int f=i==num-1 ? 255 : 0;
    fill(f);
    ellipse(x-20, y, sz*scal*s, sz*scal*s);
    angle -= (PI/num);
  }
  theta +=0.0523;
}

Code with My Comments :

int sz = 400, num=20;
float theta, angle, rad = 60;

void setup() {
  size(500, 500);
  fill(0);
  stroke(255);
  strokeWeight(8);
}

void draw() {
  background(255);
  angle=0;
  for (int i=0; i<num; i++) {
    float x = width/2-rad/2 + cos(angle)*rad;
    float y = height/2 + sin(angle)*rad;
    //any sin or cos is a valu which pingPongs from -1 to 1
    //map this changes as from 1 to 0.6
    float s = map(sin(theta+(TWO_PI/num)*i), -1, 1, 1, .6);
    float scal = 1-0.045*i;
    int f = 0;
    //this means if i equals num-1, f is 255, else, f is 0
    int f=i==num-1 ? 255 : 0;
    fill(f);
    ellipse(x-20, y, sz*scal*s, sz*scal*s);
    // angele = angle - (PI/num);
    angle -= (PI/num);
  }
  //sin value changes as theta changes
  theta +=0.0523;
}
上一篇 下一篇

猜你喜欢

热点阅读