Back to Pattern Factory

Loops · Procedural generation

Pattern Machine

Define one motif, loop it. Generative art from a tiny program.

Three lines of code can produce thousands of visual elements when wrapped in a loop. Define a small motif here, then watch the loop draw a full canvas. The same pattern powers procedural generation in games, generative-art frameworks like Processing, and the rendering of every CSS gradient.

Explore the activity to earn its passport stamp. Stamps record exploration, not mastery.

What’s happening under the hood

  • ›A loop has two parts: a body of code, and a termination condition. Each iteration produces one output.
  • ›Procedural generation is deterministic but rule-based: same rules + same seed = same output, every time. This is why game saves can encode a 1-TB world in a few KB of seed + state.
  • ›The cost of procedural content is one program + the loop's iteration count, not one file per output. Minecraft uses this to generate worlds that are effectively infinite.

Dig deeper

Phase 1 · Control Flow

The concept you just explored is taught with full depth in the formal DURA curriculum.