List<Wiggle> w;
int n=50;
void setup()
{
size(600,600);
w=new Vector();
for(int i=0; i < n; i++)
{
Wiggle wig=new Wiggle(50,map(i,0,n,50,height-50),width-100,height/2,150);
wig.gaussParam(0,0.75);
w.add(wig );
}
smooth();
background(0);
}
void draw()
{
background(0);
pushMatrix();
for(Wiggle wig:w)
{
wig.update();
wig.draw();
}
popMatrix();
for(int i=0; i < 3;i++){
int index=(int)random(0,n);
((Wiggle)w.get(index)).addGauss(random(0.5,1.3));
}
}
class Wiggle
{
float xc,yc;
float wid,hei;
float t,tstroke;
float decay;
color c=255;
float[] y,amp;
int n;
float center,sigma;
Wiggle(float xc,float yc,float wid,float hei,int n)
{
this.xc=xc;
this.yc=yc;
this.wid=wid;
this.hei=hei/pow(2,8);
this.n=n;
t=random(0,10);
tstroke=random(0,10);
y=new float[n];
amp=new float[n];
decay=random(0.90,0.95);
}
void gaussParam(float center,float sigma)
{
this.center=center;
this.sigma=sigma*sigma;
}
void update()
{
t+=0.003;
tstroke+=0.02;
for(int i=0; i < n; i++)
{
y[i]=-amp[i]*pow(2,noise(i*0.05,t)*8);
amp[i]*=decay;
}
}
void addGauss(float a)
{
float tt;
for(int i=0; i < n; i++)
{
tt=map(i,0, n-1,-2.5,2.5)-center;
amp[i]+=a*hei*(0.1+exp(-(tt*tt)/(2.0*sigma)));
}
}
void draw()
{
pushMatrix();
translate(xc,yc);
float step=1.0/(float)(n-1);
noStroke();
fill(255-c);
beginShape();
vertex(0,0);
for(int i=0; i < n; i++)
{
vertex(wid*step*i , y[i] );
}
vertex(wid,0);
endShape(CLOSE);
noFill();
stroke(c);
for(int i=0; i < n-1; i++)
{
strokeWeight(pow(2,2.5*noise(i*0.1,tstroke))-1);
line(wid*step*i , y[i],wid*step*(i+1) , y[i+1]);
}
popMatrix();
}
}