import { mountFlex } from "https://cdn.jsdelivr.net/npm/p5.flex@0.1.1/src/p5.flex.min.mjs"
import { vert, frag } from "./shader.js"
const emojis = [" ", ".", ":", "-", "=", "+", "#", "%", "8", "*", "H", "M", "#", "X"]
const [WIDTH, HEIGHT] = [2000, 1000]
const CANVAS_SIZE = [WIDTH, HEIGHT]
const TEXEL_SIZE = [1 / (WIDTH * PIXEL_DENSITY), 1 / (HEIGHT * PIXEL_DENSITY)]
let atlas = { atlas: null, cols: 0, rows: 0 }
p.createCanvas(WIDTH, HEIGHT, p.WEBGL)
p.flex({ container: { padding: "20px" } })
p.pixelDensity(PIXEL_DENSITY)
gfx = p.createGraphics(WIDTH, HEIGHT, p.WEBGL)
theShader = p.createShader(vert, frag)
theShader.setUniform("tex0", p._renderer)
theShader.setUniform("canvasSize", CANVAS_SIZE)
theShader.setUniform("texelSize", TEXEL_SIZE)
theShader.setUniform("mouse", [p.mouseX / WIDTH, p.mouseY / HEIGHT])
theShader.setUniform("time", p.frameCount / 60)
theShader.setUniform("iGrid", [cols, rows])
theShader.setUniform("iAtlas", atlas.atlas)
theShader.setUniform("iAtlasGrid", [atlas.cols, atlas.rows])
theShader.setUniform("iLength", emojis.length)
gfx.quad(-1, 1, 1, 1, 1, -1, -1, -1)
const t = p.frameCount * 0.01
p.rotateZ(p.sin(t) + p.cos(t))
p.rotateY(p.map(p.sin(t), -1, 1, -0.35, 0.35))
p.rotateX(p.map(p.cos(t), -1, 1, -0.35, 0.35))
const size = p.max(WIDTH, HEIGHT)
p.box(size, size, size * 4)
const getAtlas = ({ array, cols, unitSize, unitScale = 0.8 }) => {
const rows = p.ceil(emojis.length / cols)
const gfx = p.createGraphics(unitSize * cols, unitSize * rows)
gfx.textAlign(p.CENTER, p.CENTER)
gfx.textSize(unitSize * unitScale)
array.forEach((value, index) => {
unitSize / 2 + unitSize * (index % cols),
unitSize / 2 + unitSize * gfx.floor(index / cols)
return { atlas: gfx, cols: cols, rows: rows }