bnb({
w: width,
h: height,
numFrames: 0,
fps: 30,
record: true,
preload: (s, g) => {
g.prng = seededRandom(s.random(1000));
g.branchCount = 3;
g.layerCount = 1;
g.noiseScale = 100;
g.bordersCount = 2;
g.fieldIntensity = g.prng(1, 4);
g.colorSeed = s.int(g.prng(99));
g.noiseSeed = g.prng(0.4, 1);
},
setup: (s, g) => {
g.bg = s.color(220);
g.branches = [];
g.backgroundLayersColors = [];
g.field = new PerlinNoiseField(s, g.fieldIntensity, g.noiseScale);
g.backgroundLayersCount = s.int(g.prng(60, 100));
g.backgroundLayersColors = array(g.backgroundLayersCount).map(d => palette[randInt(1, palette.length)])
g.borderColors = array(g.bordersCount).map(d => randInt(1, palette.length))
for (let l = 0; l < g.layerCount; l++) {
for (let i = 0; i < g.branchCount; i++) {
const a = new Branch(s, g);
a.field = g.field;
a.branchesTotalCount = g.branchCount;
a.branchIndex = i;
a.resetPosition();
const rand1 = randInt(1, palette.length);
let rand2 = randInt(1, palette.length);
while (rand2 == rand1) rand2 = randInt(1, palette.length);
const rand3 = randInt(1, palette.length);
const rand4 = randInt(1, palette.length);
a.branchColor = s.color(palette[rand3]);
a.pistilColor = s.color(palette[rand4]);
a.resetPosition();
for (let j = 0; j < a.petalCount; j++) {
const p = a.petals[j];
p.petalColorBase = s.color(palette[rand1]);
p.petalColorTop = s.color(palette[rand2]);
}
g.branches.push(a);
}
}
},
draw: (s, t, g) => {
s.fill(g.bg);
s.noStroke();
s.rect(0, 0, width, height);
// background layers
for (let i = 0; i < g.backgroundLayersCount; i++) {
let y = s.map(i, 0, g.backgroundLayersCount, 0, height);
let iRatio = s.map(i, 0, g.backgroundLayersCount, 0.0, 1.0);
let c = s.lerpColor(g.bg, s.color(palette[0]), iRatio);
c = s.lerpColor(c, s.color(0), iRatio);
s.fill(c);
s.beginShape();
s.vertex(0, height);
for (let x = 0; x <= width; x +=2) {
let yMultiplier = (1 - s.abs(s.map(x, 0, width, -1, 1))) * 2;
s.vertex(x, y - 100 + s.pow( (s.noise(x * 0.01 * g.noiseSeed, y) * 100 * yMultiplier * yMultiplier), 1.3));
}
s.vertex(width, height);
s.endShape(s.CLOSE);
}
// flowers
for (let l = 0; l < g.layerCount; l++) {
let layerStartIndex = l * g.branchCount;
for (let i = 0; i < g.branchCount; i++) {
const a = g.branches[layerStartIndex + i];
a.draw(s);
}
}
// borders
const borderSize = width * (30/540);
for (let i = g.bordersCount; i > 0; i--) {
const ratio = s.map(i, 0, g.bordersCount, 0, 1);
const c = s.lerpColor(s.color(200), s.color(230), ratio);
const size = borderSize * ratio;
if (i % (g.bordersCount/2) == 0) {
s.strokeWeight(1);
s.stroke(s.color(0));
}
s.fill(c);
s.noStroke();
s.push();
const translateX = width/2;
const translateY = width/2;
s.translate(translateX, translateY);
//s.rotate(s.PI/2 * ratio);
s.rect(-translateX, -translateY, width, size);
s.rect(-translateX, height-size-translateY, width, size);
s.rect(-translateX, -translateY, size, height);
s.rect(width-size-translateX, -translateY, size, height);
s.pop();
}
const N = 10;
for (let j = 0; j<=N;j++) {
const jRatio = s.map(j, 0, N, 0, 1);
const triangleHeight = height/N;
const yMid = height * jRatio;
const y1 = yMid - triangleHeight/2;
const y2 = yMid + triangleHeight/2;
const triangleColor = s.color(palette[0]);
s.noFill();
s.stroke(triangleColor);
s.triangle(0, y1, borderSize/2, yMid, 0, y2);
s.triangle(borderSize/2, y1, 0, yMid, borderSize/2, y2);
s.triangle(width-borderSize/2, y1, width, yMid, width-borderSize/2, y2);
s.triangle(width, y1, width-borderSize/2, yMid, width, y2);
const xMid = width * jRatio;
const x1 = yMid - triangleHeight/2;
const x2 = yMid + triangleHeight/2;
s.triangle(x1, 0, xMid, borderSize/2, x2, 0);
s.triangle(x1, borderSize/2, xMid, 0, x2, borderSize/2);
s.triangle(x1, height-borderSize/2, xMid, height, x2, height-borderSize/2);
s.triangle(x1, height, xMid, height-borderSize/2, x2, height);
//s.line(0, yMid, borderSize/2, yMid);
}
}
})