Project 4: The Chaos Game (Fractals & Complex Numbers)

Build a chaos game simulator that generates fractals like the Sierpinski triangle.


Project Overview

Attribute Value
Difficulty Level 2: Intermediate
Time Estimate Weekend
Main Language Python
Alternative Languages JavaScript, C++
Knowledge Area Fractals and complex numbers
Tools Plotting tool
Main Book “Chaos and Fractals” by Peitgen, Jurgens, and Saupe

What you’ll build: A program that repeatedly applies geometric rules to generate fractal patterns.

Why it teaches math: Fractals show how simple rules produce complex structure, connecting geometry and recursion.

Core challenges you’ll face:

  • Implementing the random iteration process
  • Mapping points to pixels efficiently
  • Understanding attractors and convergence

Real World Outcome

You will generate a fractal image such as the Sierpinski triangle or a Barnsley fern.

Example Output:

$ python chaos_game.py --shape sierpinski --points 200000 --output sierpinski.png
Generated 200000 points
Saved image to sierpinski.png

Verification steps:

  • Confirm the expected fractal pattern appears
  • Increase points to improve detail

The Core Question You’re Answering

“How can random iterations create deterministic geometric structure?”

This project makes chaos measurable.


Concepts You Must Understand First

Stop and research these before coding:

  1. Iterated function systems
    • How do repeated transformations create attractors?
    • Book Reference: “Chaos and Fractals” by Peitgen et al., Ch. 2
  2. Affine transformations
    • How do scaling and translation change points?
    • Book Reference: “Linear Algebra and Its Applications” by Gilbert Strang, Ch. 2
  3. Complex plane basics
    • How do complex numbers represent 2D points?
    • Book Reference: “Complex Variables” by Churchill & Brown, Ch. 1

Questions to Guide Your Design

  1. Point generation
    • Will you start from a random point or a fixed seed?
    • How will you discard initial transient points?
  2. Rendering
    • Will you plot points directly or accumulate a heatmap?
    • How will you scale coordinates to image space?

Thinking Exercise

Sierpinski Rules

Write down the three transformations for the Sierpinski triangle and explain why each shrinks the point toward a vertex.

Questions while working:

  • Why does the pattern emerge even with random choices?
  • What happens if you change the probability of each vertex?

The Interview Questions They’ll Ask

Prepare to answer these:

  1. “What is an iterated function system?”
  2. “Why does the chaos game converge to a fractal?”
  3. “How do affine transforms create self-similarity?”
  4. “Why do you discard initial points?”
  5. “How do probabilities change the fractal?”

Hints in Layers

Hint 1: Starting Point Start with the three vertices of an equilateral triangle.

Hint 2: Next Level Pick a random vertex and move halfway toward it.

Hint 3: Technical Details Accumulate points in a pixel buffer instead of plotting one by one.

Hint 4: Tools/Debugging Increase point count until the structure is clearly visible.


Books That Will Help

Topic Book Chapter
Chaos game “Chaos and Fractals” by Peitgen et al. Ch. 2
Affine transforms “Linear Algebra and Its Applications” by Gilbert Strang Ch. 2
Complex plane “Complex Variables” by Churchill & Brown Ch. 1

Implementation Hints

  • Use integer pixel coordinates for speed.
  • Discard the first few thousand points to remove bias.
  • Keep transformations configurable for different fractals.

Learning Milestones

  1. First milestone: You can generate a clear Sierpinski triangle.
  2. Second milestone: You can produce other IFS fractals.
  3. Final milestone: You can explain why randomness still converges.