Project 19: Chaos and Mandelbrot Explorer

A self-contained deep-dive from the canonical Math from Foundations to Machine Learning curriculum.

  • Difficulty: Intermediate
  • Time: 10-18 hours
  • Language: Python (alternatives: JavaScript, Julia, C++)
  • Prerequisites: Projects 6 and 18
  • Source: HS P04

What You Will Build

Build a reproducible fractal explorer centered on complex iteration. For each pixel, map screen coordinates to a complex c, iterate z[n+1]=z[n]^2+c from zero, and record escape time when magnitude exceeds a justified threshold. Render a Mandelbrot image with configurable viewport, resolution, maximum iterations, and color mapping; support zooming and selected-point orbit diagnostics. Add a Julia mode by fixing c and varying the initial z. To preserve the source project’s broader chaos lesson, include an optional seeded triangle chaos-game view demonstrating a geometric iterated-function system and burn-in behavior.

Real World Outcome

The tool renders a deterministic Mandelbrot set, allows the user to zoom into a selected rectangle, and prints the orbit/escape iteration for clicked points. Changing maximum iterations reveals boundary detail without moving stable exterior points. Julia mode shows how one chosen parameter reshapes the set. Fixed seeds make the optional Sierpiński chaos-game image byte-reproducible and let probability changes alter point density.

Core Question

How can repeatedly applying an extremely simple rule create stable global structure, intricate boundaries, and sensitivity to tiny initial changes?

Concepts You Must Understand First

  1. Iteration and recurrence: current state is repeatedly transformed into next state.
  2. Complex multiplication: squaring doubles angle and squares modulus, driving the geometry.
  3. Escape criteria: for the quadratic Mandelbrot iteration, once |z|>2, the orbit will diverge.
  4. Coordinate mapping: pixels must map consistently to a complex viewport without distortion.
  5. Convergence, divergence, and finite evidence: “did not escape by N” is not a proof of membership.

Build Milestones

  1. Implement and unit-test complex orbit generation and escape-time classification.
  2. Map an equal-aspect complex viewport to pixels and render a baseline Mandelbrot image.
  3. Add color maps, maximum-iteration controls, zoom history, and reproducible image metadata.
  4. Add Julia-set rendering plus orbit plots for selected points.
  5. Optionally add the seeded triangle chaos game with burn-in and transform/probability controls.

Hints in Layers

  1. Test known points: c=0 remains bounded, while c=2 escapes quickly.
  2. Separate mathematical coordinates from raster coordinates and test corner mappings.
  3. Store escape iterations as a numeric array before coloring; then color changes do not require recomputation.

Common Pitfalls and Debugging

  • Symptom: the set appears stretched or mirrored. Cause: viewport aspect or pixel-y direction is wrong. Fix: test corners and enforce equal coordinate scale.
  • Symptom: every pixel is classified identically. Cause: z was not reset per pixel or c was not updated. Fix: log the first few orbits for known points.
  • Symptom: boundary points are declared definitely inside. Cause: finite iteration was treated as proof. Fix: label them “not escaped within limit.”

Definition of Done

  • Escape-time iteration passes known bounded/escaping fixtures.
  • Viewport-to-pixel mapping is tested and preserves aspect ratio.
  • Mandelbrot images are deterministic and include viewport/iteration metadata.
  • Zoom, Julia mode, and selected-orbit diagnostics work without stale state.
  • Finite-iteration limitations are explicit in the UI/report.
  • If included, chaos-game results reproduce exactly from seed and parameters.

Previous: Project 18 · Complete learning path · Next: Project 20