Experimental generative art toolkit based on JSX and esbuild. Currently just a proof of concept! Don't rely on this for anything, but feel free to poke around and check out the code locally to test it.
git clone https://github.com/mattdesl/yyz.gitcd yyz npm install
now run one of the sketches
node . sketches/DotSin.js
or...
node . sketches/RadialCircle.js
or...
node . sketches/Rings.js
or...
node . sketches/Random.js
Once it's running, open http://localhost:9966/, then you can edit the code in the selected
sketches/*.jsfile to see it re-render. Hit
Cmd/Ctrl + Sto download a higher resolution output (saved to your Downloads folder).
See canvas-sketch for a similar toolkit (without JSX/esbuild) that is much more complete.
Sketches are defined with JSX, like the following:
import { math, random } from "yyz";export const settings = { dimensions: [1280, 1280], animate: true, };
export default (props, { width, height, playhead }) => { const count = 20; const radius = 10; const margin = min(width, height) * 0.1; return math.range(count).map((i) => { const x = math.map(i, 0, count - 1, margin, width - margin); const offset = (sin((i / count) * 4 + playhead * PI * 2) * height) / 4; return ; }); };
Currently only a few basic builtins are included:
arc,
rect,
background(full-screen fill),
g(group),
point,
arcpath, and
segment. These will likely change.
You can define components just like in React et al, except the second argument is the "app state" i.e. width/height, current time in seconds, etc.
const CenteredArc = (props, { width, height }) => { // render something return };export default () => { return }
Each time you reload the page, you will get a fixed seeded randomness for the
yyzrandom utility. See the
Random.jssketch:
import { math, random } from "yyz"; import paperColors from "paper-colors"; import palettes from "nice-color-palettes";export const settings = { dimensions: [1280, 1280], };
export default (props, { width, height, playhead }) => { const count = 10; const points = []; const dim = Math.min(width, height); const margin = dim * 0.2; const background = random.pick(paperColors).hex; const palette = random.shuffle(random.pick(palettes)).slice(0, 3); for (let y = 0; y < count; y++) { for (let x = 0; x < count; x++) { const color = random.pick(palette); const px = math.mapRange(x, 0, count - 1, margin, width - margin); const py = math.mapRange(y, 0, count - 1, margin, height - margin); const radius = Math.abs(random.gaussian(0, dim * 0.02)); const p = ; points.push(p); } } return {points}; };
Check the
settingsdefined below. Then all your units will be in the units you specify, here it's
infor inches:
import { math, random } from "yyz";export const settings = { units: "in", dimensions: [12, 12], pixelsPerInch: 300, };
export default (props, { width, height, playhead }) => { const count = 10; const arcs = math.linspace(count).map((t) => { const x = math.mapRange(t, 0, 1, 0.25, 0.75 - 0.25 / 2) * width; const y = height / 2; const radius = math.mapRange(t, 0, 1, 0.05, 0.25) * width; const lineWidth = 0.005 * width; return ( ); }); return {arcs}; };
This is very early stages, and might not go anywhere, or it might go somewhere. The main motivation here is modularization of generative art code, fast iterative development, agnostic render outputs (SVG, Canvas, WebGL, JSON, GLTF, etc), and eventual GUI and "no-code" wrappers with color pickers, sliders, component wiring, etc.
MIT, see LICENSE.md for details.