xxxxxxxxxx
//Pierre MARZIN 11/04/2018
//just some fun with waves...
var nodes=[];
var nnodesH,nnodesV,nnodes;
var espH, espV, marginH, marginV;
var ampmaxH,ampmaxV;
var freq1,freq2, phase;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(200);
noFill();
noSmooth();
stroke(255);
//strokeWeight(2);
marginH=50;
marginV=50;
nnodesH=100;
nnodesV=50;
nnodes=nnodesH*nnodesV;
freq1=random(1)>.5?random(.01,.05):random(-.01,-.05);
freq2=random(1)>.5?random(.01,.05):random(-.01,-.05);
deca=0;//int(random(15));
ampmaxH=int(random(5,20));
ampmaxV=int(random(5,20));
espH=(windowWidth-2*marginH)/(nnodesH-1);
espV=(windowHeight-2*marginV)/(nnodesV-1);
for (var j=0; j<nnodesV; j++) {
for (var i=0; i<nnodesH; i++) {
nodes[j*nnodesH+i]=new Node(i, j);
}
}
esp=0;
}
function draw() {
background(0);
for (var i=0; i<nnodes; i++) {
nodes[i].update();
nodes[i].display();
}
}
function Node(i, j) {
this.i=i;
this.j=j;
this.x0=marginH+espH*i;
this.y0=marginV+espV*j;
}
Node.prototype.update=function() {
this.x=ampmaxH*cos(PI*cos(freq1*cos(.05*freq2*frameCount)*(this.i+frameCount))+map(this.j,0,nnodesV,0,TWO_PI));
this.y=ampmaxV*cos(PI*sin(freq2*cos(.07*freq1*frameCount)*(this.j+frameCount))+map(this.i,0,nnodesH,0,2*TWO_PI));
}
Node.prototype.display=function() {
var n=nodes[(this.j*nnodesH+this.i+deca)%nnodes];
push();
translate(this.x0, this.y0);
/*rotate(atan2(this.x-n.y,-n.x));
rect(n.x,n.y,3,this.x+n.y);*/
line(n.x,n.y,0,this.x);
pop();
}