Spectral Harmonograph

Spectral Harmonographs

5th October 2015

This Python + Pygame program draws the trace of 4 decaying sine waves, 2 per axis, with rainbow colours. It generates a sequence of random harmonographs. A harmonograph is a mechanical device typically seen in science museums, that has two or more pendulae with attached pens, that can draw on a sheet of paper. The pendulae are […]

Stars & Stripes

Stars and Stripes

4th July 2015

A variation on the Stars and Stripes American Flag for Independence Day. It’s an exercise in the use of transparency in Pygame. The stripes are made transparent so the stars image behind shows through.

Tower of Hanoi

Animated Tower of Hanoi

3rd July 2015

The Tower of Hanoi is a classic problem that lends itself well to a recursive solution. The story involves some poor monks having to move 64 disks of different sizes (with central holes for the pegs) from one peg to another. There are three pegs, all the disks started on the first peg (in size […]

Rainbow Flag

Rainbow Flag in Pygame

29th June 2015

This little Pygame program paints the Rainbow Flag, as used by the LGBT movement. It illustrates: Importing the Pygame library RGB colours in hexadecimal Python’s for loop using the enumerate() function Filling a rectangular area in Pygame Updating display with flip() Saving the image

Mandelbrot Set by QuadTree

Fast Mandelbrot Set by QuadTree

27th May 2015

Most Mandelbrot Set programs proceed along the display area, pixel by pixel horizontally, row by row from top to bottom. This one doesn’t. It divides up the screen into 6 horizontal squares in 2 rows, then for each one, checks the value of the escape time for the pixel at each corner. If they’re all the […]

Random Walk

18th April 2015

A colourful random walk. The basic idea is very simple: choose a random heading in the range 0:360 degrees. Step in that direction. Choose another random heading & step again. Do this 2,000 times. As a bonus, we go through all the colours of the rainbow (or something similar) from beginning to end. Dealing with […]

Turtle Star

18th April 2015

A very simple Turtle program. Turtle can draw intricate shapes using programs that repeat simple moves. Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966. Imagine a robotic turtle starting at (0, 0) in the […]

Naive Mandelbrot Set

17th April 2015

This is your basic Mandelbrot Set plotter. Very little effort made to speed it up, except for plotting top & bottom pixels together as they’re mirrored across the x-axis. Later I’ll show you some much faster programs! The heart of this program is the iteration of z2+c where c is a point in the complex […]

Fractal Tree

17th April 2015

This program draws a ‘tree’ by drawing a trunk (initially; later it’s a branch) and appending a tree, recursively. Uses Pillow.