Blog

A blog of Python-related topics and code.

Generating an SVG clock face

This is a simple Python function to generate a clock face indicating a specified time. It can be used in the script below to generate 1, 2, 4 or 6 faces indicating random times to teach children how to tell the time. Run this script from the command line as

Truchet Tiles

Truchet Tiles are decorated squares which can tile a plane to create a pattern. For example, the four tiles:

Reaching Orbit

The following code illustrates the effect of the initial velocity on the dynamics of an object released in a gravitational field. A very simple numerical integration of the equation of motion gives the trajectory, which is plotted below for four different initial speeds for a rocket released at 200 km altitude parallel to the Earth's surface. At this altitude the speed needed for a circular orbit is about 7.8 km/s. You can read more about this kind of simulation at the Wikipedia page for Newton's cannonball.

The bounding box of a rotated object

The following code plots a two-dimensional object and its bounding box for several rotations about an arbitrary point. Three types of bounding box are considered: (1) the original bounding box, rotated by the same amount as the object, (2) the bounding box to that bounding box (such that its sides remain parallel to the axes), and (3) the bounding box to the rotated object with sides parallel to the axes).

Moiré patterns in a pair of hexagonal lattices

A Moiré pattern is an interference pattern that occurs when two grids of repeating lines or shapes are rotated by a small amount relative to one another (oblig. xkcd).