Harmonograph

Multi-pendulum Harmonograph simulator using numpy and matplotlib

22nd June 2017

This is a simple harmonograph simulator to generate random-ish harmonographs. It asks for the number of pendulums, and exits if the number is 0. It also asks for the frequency spread, which means roughly, how far from integer may the frequencies go. The nearer to integer they are, the ‘cleaner’ looking the harmonographs are, but […]

Sigmoid NN

A Neural Network in Python, Part 2: activation functions, bias, SGD, etc.

9th February 2017

This is Part 2 of A Neural Network in Python, which was a very simple neural network to learn the XOR function. This part builds on that example to demonstrate more activation functions, learning a simple math function, adding a bias, improvements to the initial random weights, stochastic gradient descent, mean square error loss function, […]

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 […]

Harmonograph in Pygame

3rd October 2015

You may have seen those devices at the Science Museum or Exploratorium or Techniquest… There’s a drawing surface and some arrangement of pendula with a pen touching the paper on the drawing surface, set in motion it draws these pretty pictures, which are essentially decaying Lissajous figures. Lissajous figures are often seen in old sci-fi […]

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

A Graphical Dice Simulator

31st May 2015

This PyGame program simulates the roll of a die (or dice if you prefer). It’s a fairly simple, straightforward thing to do, though it may be worth noting that the spots display is oh-so-slightly clever. Some spots appear in more than one number, e.g. the middle spot is in all the odd numbers, hence the […]

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 […]

Extensible Harmonographs

Extensible Harmonograph

18th May 2015

Often seen in science museums, the harmonograph is a device that combines wave motions (e.g. from some pendulums) to move a pen resting on a sheet of paper. These movements result in attractive patterns. This device can be simulated easily in a computer program such as the following one. The principle is that the wavy […]

Easy Graph Plotting with Pyplot

7th May 2015

Graphs (also known as charts) are an indispensible visual aid for conveying a lot of data in an easy-to-digest form. Everyone is familiar with graphs in everyday life, such as those showing trends over time, e.g. world population, global warming, the cost of living, interest rates, etc. They are of fundamental importance in the STEM […]