Periodicity

posted by on 2013.03.01, under Processing
01:

Here’s a little code in Processing exploring periodic motion. The single balls have been assigned an angular velocity consisting of “even harmonics”, while the amplitude of the single oscillation is constant up to some tiny random factor, to make the whole animation look more “natural”.

int p=50;
float[] y= new float[p];
float[] r= new float[p+1];
float[] omega= new float[p+1];
float[] amp= new float[p+1];
float t=0;
float s=0;
float b=0;

void setup() {
  for (int i=0;i<y.length;i++){
    y[i]=i;
  };
  omega[0]=0;
  for (int i=1;i<omega.length;i++){
    omega[i]=i*2;
    amp[i]=20+random(-1.0,1.0);
  };
size(400, 400);
 background(255);
}

void draw() {
  background(255);

for (int i=0;i<r.length;i++){
  r[i]=amp[i]*sin(omega[i]*t/2);
};
  for (int i=0;i<y.length;i++){
    stroke(50);
    strokeWeight(3);
  line(width/2+r[i],y[i]*600/p,width/2+r[i+1],y[i]*600/p+600/p);
  fill(int(abs(map(sin(i*t/2),-1,1,-255,255))));
  strokeWeight(1);
  ellipse(width/2+r[i],y[i]*600/p,10,10);
} ;
t +=0.008;
b++;
};

Click below to start/stop the animation.

pagetop