home / skills / 404kidwiz / claude-supercode-skills / algorithmic-art-skill

algorithmic-art-skill skill

/algorithmic-art-skill

This skill helps you create generative art, data-driven visualizations, and interactive installations using p5.js and JavaScript.

npx playbooks add skill 404kidwiz/claude-supercode-skills --skill algorithmic-art-skill

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
9.8 KB
---
name: algorithmic-art
description: Expert in generative art, creative coding, and mathematical visualizations using p5.js and JavaScript.
---

# Algorithmic Artist

## Purpose

Provides creative coding expertise specializing in generative art, mathematical visualizations, and interactive installations using p5.js. Creates visual art through code with flow fields, particle systems, noise algorithms, and algorithmic patterns for creative and educational purposes.

## When to Use

- Creating generative artwork (NFTs, wallpapers, posters)
- Building interactive data visualizations
- Simulating natural phenomena (flocking, cellular automata)
- Designing mathematical patterns (fractals, tessellations)
- Teaching creative coding concepts

---
---

## 2. Decision Framework

### Algorithm Selection

```
What is the visual goal?
│
├─ **Organic / Natural**
│  ├─ Texture? → **Perlin Noise / Simplex Noise**
│  ├─ Movement? → **Flow Fields / Vector Fields**
│  └─ Growth? → **L-Systems / Diffusion Limited Aggregation (DLA)**
│
├─ **Geometric / Structured**
│  ├─ Repetition? → **Grid Systems / Tilemaps**
│  ├─ Recursion? → **Fractals (Mandelbrot, Sierpinski)**
│  └─ Division? → **Voronoi / Delaunay Triangulation**
│
└─ **Simulation**
   ├─ Physics? → **Verlet Integration / Springs**
   └─ Behavior? → **Boids (Flocking) / Cellular Automata**
```

### Randomness Strategy

| Type | Function | Description |
|------|----------|-------------|
| **Uniform** | `random()` | Complete chaos. White noise. |
| **Gaussian** | `randomGaussian()` | Bell curve. Most values near mean. |
| **Perlin** | `noise()` | Smooth, gradient randomness. "Cloud-like". |
| **Seeded** | `randomSeed()` | Deterministic. Same output every time. |

**Red Flags → Escalate to `threejs-pro`:**
- Requirement for heavy 3D rendering (p5.js WebGL mode is limited compared to Three.js)
- Complex lighting/shadow requirements
- VR/AR integration needed

---
---

### Workflow 2: Recursive Tree (Fractal)

**Goal:** Draw a tree using recursion.

**Steps:**

1.  **Branch Function**
    -   Draw line of length `len`.
    -   Translate to end of line.
    -   Rotate `theta`.
    -   Call `branch(len * 0.67)`.
    -   Rotate `-theta * 2`.
    -   Call `branch(len * 0.67)`.

2.  **Termination**
    -   Stop when `len < 2`.

---
---

## Core Capabilities

### Generative Art Creation
- Creates visual artwork using mathematical algorithms and randomness
- Implements flow fields, particle systems, and noise-based visualizations
- Generates geometric patterns, fractals, and tessellations
- Creates procedural animations and interactive installations

### Mathematical Visualization
- Implements algorithms for data-driven visual representations
- Creates visualizations of mathematical concepts (fractals, chaos theory)
- Builds interactive simulations of natural phenomena
- Develops educational visualizations for mathematical concepts

### Performance Optimization
- Optimizes rendering performance for complex generative systems
- Implements canvas/WebGL optimizations for real-time artwork
- Creates efficient particle systems and spatial data structures
- Manages memory usage for large-scale generative projects

### Creative Technology Integration
- Integrates generative art with web technologies
- Creates exportable artwork in various formats (PNG, SVG, GIF, video)
- Implements interactivity and user input responsiveness
- Develops installations combining code with physical outputs

---
---

## 5. Anti-Patterns & Gotchas

### ❌ Anti-Pattern 1: Heavy Computation in `draw()`

**What it looks like:**
-   Creating 10,000 objects every frame.
-   Resizing array every frame.

**Why it fails:**
-   FPS drops to 5. Browser hangs.

**Correct approach:**
-   **Pre-calculate:** Generate static geometry in `setup()`.
-   **Pool Objects:** Reuse particles instead of `new Particle()`.

### ❌ Anti-Pattern 2: Ignoring Resolution

**What it looks like:**
-   Hardcoding `width = 500`.
-   Art looks pixelated on Retina screens.

**Why it fails:**
-   Looks bad on high-DPI monitors or prints.

**Correct approach:**
-   `pixelDensity(2)` (or higher).
-   Use relative units (`width * 0.5`) instead of absolute pixels.

### ❌ Anti-Pattern 3: Pure Randomness

**What it looks like:**
-   `fill(random(255), random(255), random(255))`

**Why it fails:**
-   "Clown vomit" aesthetic. No cohesion.

**Correct approach:**
-   **Curated Palettes:** Pick 5 colors and stick to them.
-   **Constraints:** Randomness should be the spice, not the meal.

---
---

## 7. Quality Checklist

**Visuals:**
-   [ ] **Resolution:** Sharp on Retina (`pixelDensity`).
-   [ ] **Composition:** Follows Rule of Thirds or Golden Ratio.
-   [ ] **Color:** Palette is cohesive (not pure random).

**Performance:**
-   [ ] **FPS:** 60fps for interactive, any FPS for static generation.
-   [ ] **Memory:** No memory leaks (arrays growing infinitely).

**Code:**
-   [ ] **Seeding:** `randomSeed()` used for reproducibility.
-   [ ] **Resizing:** `windowResized()` handles layout changes.
-   [ ] **Modularity:** Classes used for complex entities (Agent, Particle).

## Examples

### Example 1: Interactive Data Visualization

**Scenario:** A data analyst wants to visualize population growth data as an animated circle packing visualization where circle sizes represent population figures.

**Approach:**
1. **Data Processing**: Load CSV data and normalize population values to circle radii
2. **Circle Packing Algorithm**: Implement iterative circle placement with collision detection
3. **Color Mapping**: Create HSL color palette based on geographic region
4. **Interactivity**: Add mouse hover to display country name and population

**Key Implementation:**
```javascript
// Circle packing with growth animation
function draw() {
  background(20);
  for (let circle of circles) {
    if (!circle.grown) {
      circle.grow();
      if (circle.grown) {
        circle.resolveCollisions(circles);
      }
    }
    circle.display();
  }
}
```

**Result:** Interactive visualization showing 50 countries with color-coded regions, smooth growth animations, and hover tooltips.

### Example 2: Generative Art NFT Collection

**Scenario:** An artist wants to create a 10,000-piece NFT collection with programmatically generated flowers, ensuring rarity distribution and visual cohesion.

**Approach:**
1. **Trait Architecture**: Define layers (background, stem, petals, center) with rarity weights
2. **Hash-based Generation**: Use hash function to deterministically select traits
3. **Color Harmony**: Implement HSL-based color palettes with complementary accent colors
4. **Batch Generation**: Generate and export 10,000 images with metadata

**Key Features:**
- 5 background types with varying rarity (common to legendary)
- 20 flower types with 4 color variations each
- Guaranteed visual uniqueness while maintaining aesthetic cohesion
- Metadata JSON generation for Opensea compatibility

### Example 3: Educational Physics Simulation

**Scenario:** A physics teacher needs an interactive demonstration of particle collision and momentum conservation for a high school class.

**Approach:**
1. **Particle System**: Create particles with position, velocity, and mass
2. **Collision Detection**: Implement elastic collision physics
3. **Controls**: Add sliders for gravity, elasticity, and particle count
4. **Visualization**: Show velocity vectors and momentum totals in real-time

**Educational Features:**
- Adjustable parameters (gravity coefficient, wall bounce)
- Pause/step controls for detailed analysis
- Real-time momentum calculations displayed
- Trail effect showing particle paths

## Best Practices

### Visual Design Excellence

- **Plan Your Composition**: Sketch or use design tools before coding complex visualizations
- **Use Color Thoughtfully**: Create intentional palettes rather than random colors
- **Apply Design Principles**: Golden ratio, rule of thirds, visual hierarchy
- **Consider Accessibility**: Ensure sufficient contrast and consider colorblind-friendly palettes
- **Test at Multiple Resolutions**: Verify visual integrity from favicon to poster size

### Performance Optimization

- **Pre-calculate When Possible**: Move static geometry generation to setup()
- **Pool Objects**: Reuse particle objects instead of creating new ones each frame
- **Limit Array Operations**: Cache array length, avoid array methods in draw() loops
- **Use pixelDensity Wisely**: Set appropriately for target display (1 for performance, 2 for Retina)
- **Profile Regularly**: Use browser dev tools to identify bottlenecks

### Algorithm Selection

- **Match Algorithm to Goal**: Noise for organic, recursion for fractals, boids for behavior
- **Start Simple**: Implement basic version first, add complexity incrementally
- **Understand the Math**: Know the underlying mathematics of algorithms you use
- **Iterate Parameters**: Small parameter changes often yield dramatically different results
- **Combine Techniques**: Layer multiple algorithms for complex visuals (noise + flow fields + particles)

### Code Organization

- **Use Classes for Complex Entities**: Particle, Agent, Vehicle classes for organization
- **Separate Configuration**: Extract parameters to configurable objects
- **Document Your Algorithms**: Add comments explaining the math and logic
- **Create Utility Functions**: Modularize common operations (color generation, random ranges)
- **Version Your Work**: Save iterations to understand your creative process

### Export and Distribution

- **Preserve Reproducibility**: Use randomSeed() for deterministic exports
- **Optimize for Target**: Export at appropriate resolution and format
- **Include Metadata**: Add creator attribution and generation parameters
- **Test Export Pipeline**: Verify exported images match on-screen appearance
- **Backup Source Code**: Keep editable source for future modifications

Overview

This skill is an expert in generative art, creative coding, and mathematical visualization using p5.js and JavaScript. It helps design and produce algorithmic visuals—from flow fields and particle systems to fractals and tessellations—optimized for interactive and exportable outputs. The skill balances aesthetics, performance, and reproducibility for creative and educational projects.

How this skill works

It selects algorithms and randomness strategies based on the visual goal (organic, geometric, or simulation), then implements them in p5.js with performance-aware patterns (pre-calculation, object pooling, pixelDensity handling). It provides templates and patterns for recursion, noise, flow fields, boids, and procedural trait systems, plus export and interactivity hooks for PNG/SVG/GIF/video and metadata generation. It flags heavy 3D or VR needs for a three.js-style approach.

When to use it

  • Creating generative artwork (wallpapers, prints, NFTs) with programmatic variation
  • Building interactive data-driven visualizations or educational simulations
  • Simulating natural phenomena like flocking, cellular automata, or diffusion
  • Designing mathematical patterns: fractals, tessellations, Voronoi diagrams
  • Optimizing canvas/WebGL sketches for real-time performance

Best practices

  • Match algorithm to intent: noise for organic texture, recursion for fractals, boids for behavior
  • Pre-calculate static geometry in setup() and pool particles to avoid per-frame allocations
  • Use seeded randomness for reproducible outputs and batch exports
  • Design cohesive palettes and apply composition rules (rule of thirds, golden ratio)
  • Test and set pixelDensity for target displays; provide windowResized() handling
  • Extract parameters into config objects and organize code into classes and utilities

Example use cases

  • Generate a deterministic NFT collection with layered traits, rarity weights, and batch export + metadata
  • Build an interactive circle-packing data visualization that maps CSV values to radii and shows hover tooltips
  • Create a classroom physics demo of elastic collisions with sliders for gravity and real-time momentum readouts
  • Produce large-scale generative posters using flow fields and high-resolution exports with pixelDensity tuned
  • Develop an installation sketch that maps live input (mouse, MIDI, or sensors) to particle behavior for responsive visuals

FAQ

Can this skill handle 3D scenes and advanced lighting?

p5.js WebGL is supported for basic 3D, but for complex lighting, shadows, or VR/AR workflows, a dedicated three.js approach is recommended.

How do I ensure reproducible outputs across runs?

Use randomSeed() and deterministic hash-based trait selection; record the seed and generation parameters with exported assets.

What are common performance pitfalls to avoid?

Avoid creating large numbers of objects each frame, resizing arrays per frame, and heavy per-frame allocations. Precompute, pool objects, and profile with browser dev tools.