name: p5js
description: "Production pipeline for interactive and generative visual art using p5.js. Creates browser-based sketches, generative art, data visualizations, interactive experiences, 3D scenes, audio-reactive visuals, and motion graphics โ exported as HTML, PNG, GIF, MP4, or SVG. Covers: 2D/3D rendering, noise and particle systems, flow fields, shaders (GLSL), pixel manipulation, kinetic typography, WebGL scenes, audio analysis, mouse/keyboard interaction, and headless high-res export. Use when users request: p5.js sketches, creative coding, generative art, interactive visualizations, canvas animations, browser-based visual art, data viz, shader effects, or any p5.js project."
version: 1.0.0
metadata:
hermes:
tags: [creative-coding, generative-art, p5js, canvas, interactive, visualization, webgl, shaders, animation]
related_skills: [ascii-video, manim-video, excalidraw]
p5.js Production Pipeline
Creative Standard
This is visual art rendered in the browser. The canvas is the medium; the algorithm is the brush.
Before writing a single line of code, articulate the creative concept. What does this piece communicate? What makes the viewer stop scrolling? What separates this from a code tutorial example? The user's prompt is a starting point โ interpret it with creative ambition.
First-render excellence is non-negotiable. The output must be visually striking on first load. If it looks like a p5.js tutorial exercise, a default configuration, or "AI-generated creative coding," it is wrong. Rethink before shipping.
Go beyond the reference vocabulary. The noise functions, particle systems, color palettes, and shader effects in the references are a starting vocabulary. For every project, combine, layer, and invent. The catalog is a palette of paints โ you write the painting.
Be proactively creative. If the user asks for "a particle system," deliver a particle system with emergent flocking behavior, trailing ghost echoes, palette-shifted depth fog, and a background noise field that breathes. Include at least one visual detail the user didn't ask for but will appreciate.
Dense, layered, considered. Every frame should reward viewing. Never flat white backgrounds. Always compositional hierarchy. Always intentional color. Always micro-detail that only appears on close inspection.
Cohesive aesthetic over feature count. All elements must serve a unified visual language โ shared color temperature, consistent stroke weight vocabulary, harmonious motion speeds. A sketch with ten unrelated effects is worse than one with three that belong together.
Modes
| Mode | Input | Output | Reference |
| ------ | ------- | -------- | ----------- |
| Generative art | Seed / parameters | Procedural visual composition (still or animated) | references/visual-effects.md |
| Data visualization | Dataset / API | Interactive charts, graphs, custom data displays | references/interaction.md |
| Interactive experience | None (user drives) | Mouse/keyboard/touch-driven sketch | references/interaction.md |
| Animation / motion graphics | Timeline / storyboard | Timed sequences, kinetic typography, transitions | references/animation.md |
| 3D scene | Concept description | WebGL geometry, lighting, camera, materials | references/webgl-and-3d.md |
| Image processing | Image file(s) | Pixel manipulation, filters, mosaic, pointillism | references/visual-effects.md ยง Pixel Manipulation |
| Audio-reactive | Audio file / mic | Sound-driven generative visuals | references/interaction.md ยง Audio Input |
| Layer | Tool | Purpose | |
| ------- | ------ | --------- | |
| Core | p5.js 1.11.3 (CDN) | Canvas rendering, math, transforms, event handling | |
| 3D | p5.js WebGL mode | 3D geometry, camera, lighting, GLSL shaders | |
| Audio | p5.sound.js (CDN) | FFT analysis, amplitude, mic input, oscillators | |
| Export | Built-in saveCanvas() / saveGif() / saveFrames() | PNG, GIF, frame sequence output | |
| Capture | CCapture.js (optional) | Deterministic framerate video capture (WebM, GIF) | |
| Headless | Puppeteer + Node.js (optional) | Automated high-res rendering, MP4 via ffmpeg | |
| SVG | p5.js-svg 1.6.0 (optional) | Vector output for print โ requires p5.js 1.x | |
| Natural media | p5.brush (optional) | Watercolor, charcoal, pen โ requires p5.js 2.x + WEBGL | |
| Texture | p5.grain (optional) | Film grain, texture overlays | |
| Fonts | Google Fonts / loadFont() | Custom typography via OTF/TTF/WOFF2 | |
| Dimension | Options | Reference | |
| ----------- | --------- | ----------- | |
| Color system | HSB/HSL, RGB, named palettes, procedural harmony, gradient interpolation | references/color-systems.md | |
| Noise vocabulary | Perlin noise, simplex, fractal (octaved), domain warping, curl noise | references/visual-effects.md ยง Noise | |
| Particle systems | Physics-based, flocking, trail-drawing, attractor-driven, flow-field following | references/visual-effects.md ยง Particles | |
| Shape language | Geometric primitives, custom vertices, bezier curves, SVG paths | references/shapes-and-geometry.md | |
| Motion style | Eased, spring-based, noise-driven, physics sim, lerped, stepped | references/animation.md | |
| Typography | System fonts, loaded OTF, textToPoints() particle text, kinetic | references/typography.md | |
| Shader effects | GLSL fragment/vertex, filter shaders, post-processing, feedback loops | references/webgl-and-3d.md ยง Shaders | |
| Composition | Grid, radial, golden ratio, rule of thirds, organic scatter, tiled | references/core-api.md ยง Composition | |
| Interaction model | Mouse follow, click spawn, drag, keyboard state, scroll-driven, mic input | references/interaction.md | |
| Blend modes | BLEND, ADD, MULTIPLY, SCREEN, DIFFERENCE, EXCLUSION, OVERLAY | references/color-systems.md ยง Blend Modes | |
| Layering | createGraphics() offscreen buffers, alpha compositing, masking | references/core-api.md ยง Offscreen Buffers | |
| Texture | Perlin surface, stippling, hatching, halftone, pixel sorting | references/visual-effects.md ยง Texture Generation | |
| Format | Method | Command | |
| -------- | -------- | --------- | |
| PNG | saveCanvas('output', 'png') in keyPressed() | Press 's' to save | |
| High-res PNG | Puppeteer headless capture | node scripts/export-frames.js sketch.html --width 3840 --height 2160 --frames 1 | |
| GIF | saveGif('output', 5) โ captures N seconds | Press 'g' to save | |
| Frame sequence | saveFrames('frame', 'png', 10, 30) โ 10s at 30fps | Then ffmpeg -i frame-%04d.png -c:v libx264 output.mp4 | |
| MP4 | Puppeteer frame capture + ffmpeg | bash scripts/render.sh sketch.html output.mp4 --duration 30 --fps 30 | |
| SVG | createCanvas(w, h, SVG) with p5.js-svg | save('output.svg') | |
| Metric | Target | ||
| -------- | -------- | ||
| Frame rate (interactive) | 60fps sustained | ||
| Frame rate (animated export) | 30fps minimum | ||
| Particle count (P2D shapes) | 5,000-10,000 at 60fps | ||
| Particle count (pixel buffer) | 50,000-100,000 at 60fps | ||
| Canvas resolution | Up to 3840x2160 (export), 1920x1080 (interactive) | ||
| File size (HTML) | < 100KB (excluding CDN libraries) | ||
| Load time | < 2s to first frame | ||
| File | Contents | ||
| ------ | ---------- | ||
references/core-api.md | Canvas setup, coordinate system, draw loop, push()/pop(), offscreen buffers, composition patterns, pixelDensity(), responsive design | ||
references/shapes-and-geometry.md | 2D primitives, beginShape()/endShape(), Bezier/Catmull-Rom curves, vertex() systems, custom shapes, p5.Vector, signed distance fields, SVG path conversion | ||
references/visual-effects.md | Noise (Perlin, fractal, domain warp, curl), flow fields, particle systems (physics, flocking, trails), pixel manipulation, texture generation (stipple, hatch, halftone), feedback loops, reaction-diffusion | ||
references/animation.md | Frame-based animation, easing functions, lerp()/map(), spring physics, state machines, timeline sequencing, millis()-based timing, transition patterns | ||
references/typography.md | text(), loadFont(), textToPoints(), kinetic typography, text masks, font metrics, responsive text sizing | ||
references/color-systems.md | colorMode(), HSB/HSL/RGB, lerpColor(), paletteLerp(), procedural palettes, color harmony, blendMode(), gradient rendering, curated palette library | ||
references/webgl-and-3d.md | WEBGL renderer, 3D primitives, camera, lighting, materials, custom geometry, GLSL shaders (createShader(), createFilterShader()), framebuffers, post-processing | ||
references/interaction.md | Mouse events, keyboard state, touch input, DOM elements, createSlider()/createButton(), audio input (p5.sound FFT/amplitude), scroll-driven animation, responsive events | ||
references/export-pipeline.md | saveCanvas(), saveGif(), saveFrames(), deterministic headless capture, ffmpeg frame-to-video, CCapture.js, SVG export, per-clip architecture, platform export (fxhash), video gotchas | ||
references/troubleshooting.md | Performance profiling, per-pixel budgets, common mistakes, browser compatibility, WebGL debugging, font loading issues, pixel density traps, memory leaks, CORS | ||
templates/viewer.html | Interactive viewer template: seed navigation (prev/next/random/jump), parameter sliders, download PNG, responsive canvas. Start from this for explorable generative art |
Creative Divergence (use only when user requests experimental/creative/unique output)
If the user asks for creative, experimental, surprising, or unconventional output, select the strategy that best fits and reason through its steps BEFORE generating code.
Conceptual Blending
1. Name two distinct visual systems (e.g., particle physics + handwriting)
2. Map correspondences (particles = ink drops, forces = pen pressure, fields = letterforms)
3. Blend selectively โ keep mappings that produce interesting emergent visuals
4. Code the blend as a unified system, not two systems side-by-side
SCAMPER Transformation
Take a known generative pattern (flow field, particle system, L-system, cellular automata) and systematically transform it:
Distance Association
1. Anchor on the user's concept (e.g., "loneliness")
2. Generate associations at three distances:
- Close (obvious): empty room, single figure, silence
- Medium (interesting): one fish in a school swimming the wrong way, a phone with no notifications, the gap between subway cars
- Far (abstract): prime numbers, asymptotic curves, the color of 3am
3. Develop the medium-distance associations โ they're specific enough to visualize but unexpected enough to be interesting