xxxxxxxxxx
68
class Wave{
constructor(x,y,length){
this.x =x;
this.y =y;
this.step = 10;
this.length = length * this.step;
this.rry = [];
this.inc = 0.1;
this.initArray();
}
initArray(){
let ynoise = random() * this.inc;
for(let i=0; i<this.length; i+=this.step){
let perlin = noise(ynoise);
this.rry.unshift(createVector((this.x + i) ,this.y * perlin));
ynoise+=0.1;
}
}
update(){
let ynoise = frameCount * 0.01;
beginShape();
noFill();
stroke(255);
for(let i=0; i<this.rry.length; i+=1){
let _x = this.rry[i].x;
let _y = this.rry[i].y;
let perlin = noise(ynoise);
this.rry[i].y = this.y * perlin;
curveVertex(_x,_y);
ynoise+=this.inc;
}
endShape();
}
display(){
push();
this.update();
pop();
}
}