class Nodes { constructor(xMin, xMax, yMin, yMax, dx, dy, zShif, yShift, buffSize, nIters, baseF, locTransformer) { this.xMin = xMin; this.xMax = xMax; this.yMin = yMin; this.yMax = yMax; this.dx = dx; this.dy = dy; this.yShift = yShift + fxRandRanged(-yShift * 0.5, yShift * 0.5); this.zShif = zShif; this.fscale = buffSize / (Math.abs(this.xMax - this.xMin) + Math.abs(this.yMax - this.yMin)); this.fscale = this.fscale + fxRandRanged(-0.1 * this.fscale, 0.1 * this.fscale); this.nIters = nIters; this.currIters = 0; this.nodes = []; for (let x = this.xMin; x <= this.xMax; x += this.dx) { var yNodes = []; for (let y = this.yMin; y <= this.yMax; y += this.dy) { yNodes.push(baseF(x , y, this.zShif, this.yShift)); } this.nodes.push(yNodes); } this.locTransformer = locTransformer; } setPalette (color1, color2) { this.color1 = color1; this.color2 = color2; this.diff = [ Math.abs(this.color1[0] - this.color2[0]), Math.abs(this.color1[1] - this.color2[1]), Math.abs(this.color1[2] - this.color2[2]), ] } getColor(x, y, z) { z = z + this.zShif; y = y + this.yShift; var redC = this.diff[0] * Math.log(y); var greenC = this.diff[1] + 10 * Math.sin(z); var blueC = this.diff[2] + 10 * Math.sqrt(x); redC = Math.abs(redC % this.diff[0]) + Math.min(this.color1[0], this.color2[0]); greenC = Math.abs(greenC % this.diff[1]) + Math.min(this.color1[1], this.color2[1]); blueC = Math.abs(blueC % this.diff[2]) + Math.min(this.color1[2], this.color2[2]); return [redC, greenC, blueC]; } draw (buffer) { if (this.currIters >= this.nIters) { return; } for (let k = 0; k < 50; k++) { for (let i = 0; i < this.nodes.length; i++) { buffer.beginShape(POINTS); var x = (this.xMin + i * this.dx) * this.fscale; for (let j = 0; j < this.nodes[i].length; j++) { var y = (this.yMin + j * this.dy) * this.fscale; var z = this.nodes[i][j] * this.fscale; var loc = this.locTransformer(x, y, z, this.zShif, this.yShift); buffer.stroke(...this.getColor(...loc)); buffer.curveVertex(...loc); } buffer.endShape(CLOSE); } } this.currIters += 50; } }