import { mountFlex } from "https://cdn.jsdelivr.net/npm/p5.flex@0.2.0/src/p5.flex.min.mjs"
import { mountGrid } from "./Grid.js"
import { BS, recur } from "./L-system.js"
import { sleep, Border, randomPoints, getTheme, getBSType } from "./tools.js"
const canvasW = p.random([800, 1000, 1200, 1600])
const canvasH = p.random([800, 1000, 1200, 1600])
const lock = p.random() < 0.1 ? true : false
const lockType = getBSType(p)
const getAspectRatio = (width, height) => {
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b))
const divisor = gcd(width, height)
return `${width / divisor}/${height / divisor}`
Layout: getAspectRatio(canvasW, canvasH),
MixedThemes: p.random([true, false]),
Species: lock ? "Monotonous" : "Diverse",
Darkness: p.random() < 0.1,
p.createCanvas(canvasW, canvasH)
p.flex({ container: { padding: "20px" } })
const bgColor = [p.random(225, 255), p.random(225, 255), p.random(225, 255)]
p.parentBgColor(...bgColor.map((c) => c * 0.94))
p.containerBgColor(...bgColor.map((c) => c * 0.94))
p.Grid({ cols, rows }).generate(content)
const ground = async () => {
for (let i = 0; i < 2000; i++) {
const posX = p.random(p.width)
const posY = p.random(p.height - 75 - 80 * (p.noise(posX * 0.0025) * 2 - 1), p.height)
randomPoints(p, posX, posY, 30, 30, 100, "brown")
i % 100 === 0 && await sleep(1)
for (let i = 0; i < 750; i++) {
const posX = p.random(p.width)
const posY = p.random(p.height - 80 - 80 * (p.noise(posX * 0.0025) * 2 - 1), p.height)
if (p.random() < 0.05) randomPoints(p, posX, posY, 30, 30, 100, "brown")
else randomPoints(p, posX, posY, 30, 30, 100, features.Theme)
i % 100 === 0 && await sleep(1)
const plants = async () => {
for (let i = 0; i < 35; i++) {
const type = lock ? lockType : getBSType(p)
const sentence = recur(bs, bs.axiom)
const r = p.random(1, 10)
p.translate(p.random(p.width), p.height - (70 - 2 * i))
for (let i = 0; i < sentence.length; i++) {
if (features.MixedThemes && p.random() < 0.1)
await bs.methods[char](r, getTheme(p))
else await bs.methods[char](r, features.Theme)
i % 3 === 0 && p.filter(p.BLUR, 1)
i % 4 === 0 && p.filter(p.DILATE)
i % 5 === 0 && p.filter(p.POSTERIZE, 40)
i % 6 === 0 && p.filter(p.ERODE)
p.filter(p.POSTERIZE, 40)
if (features.Darkness) p.filter(p.INVERT)
Swirl(0, 0, pattern_size)
randomPoints(p, 0, 0, 200 * itemScale, 200 * itemScale, 300 * itemScale, features.Theme)
const Swirl = (x, y, size) => {
const start = p.int(p.random(0, 360))
p.stroke(p.random(180, 255), 48)
p.strokeWeight(p.random(0.5, 0.8) * itemScale)
for (let i = start; i < end; i++) {
p.curveVertex(p.cos(i) * r, p.sin(i) * r)