xxxxxxxxxx
62
class Water {
constructor(letterPoints, opacity, beginX, beginY, offset) {
this.beginX = beginX;
this.beginY = beginY;
this.letterPoints = letterPoints; //this is the array of points that will be modified
this.textSize = 100;
this.opacity = opacity;
this.offset = offset;
//go over every letter
for (let i = 0; i < this.letterPoints.length; i++) {
//go over every point in the letter and move to correct position
for (let j = 0; j < this.letterPoints[i].length; j++) {
this.letterPoints[i][j].x += this.beginX;
this.letterPoints[i][j].y += this.beginY;
}
}
}
show() {
//fill blue
push();
fill(0, 100, 255, this.opacity);
noStroke();
for (let i = 0; i < this.letterPoints.length; i++) {
push();
beginShape();
for (let j = 0; j < this.letterPoints[i].length; j++) {
let x = this.letterPoints[i][j].x;
let y = this.letterPoints[i][j].y;
//make the water ripple
let rippleFactor = map(this.textSize, MINFONTSIZE, MAXFONTSIZE, 0, 2);
y += noise(frameCount * 0.02 + j * 0.02) * rippleFactor;
//make the water wave
let waveHeight = map(this.textSize, MINFONTSIZE, MAXFONTSIZE, 1, 2);
y += waveHeight * sin(frameCount * 0.02 * (i + 1) + this.offset);
vertex(x, y);
}
endShape(CLOSE);
pop();
}
pop();
//make the water lighter and darker
this.opacity = map(
cos(frameCount * this.offset * 0.005),
-1,
1,
MINOPACITY,
MAXOPACITY
);
}
}