Snakes, Squid and LEGO
Three more scripts have joined the mazes, maps and glyphs in my fractals repo: a maze drawn by random walks that can turn into a pit of snakes, an octopus rubber stamp, and the same octopus built out of LEGO. As before, everything is seeded, so the same number always gives the same picture.
Random walk mazes
maze_walk.py is a simpler take on maze.py. Instead of posters with a solution drawn in, it carves a maze with the same three algorithms (backtracker, Aldous-Broder and Wilson) and draws the passages as chunky squares on a grid.
The colours can show two different things. Coloured by distance, each cell’s hue is how far you’d have to walk from the start to reach it, so the rainbow runs out from the top-left corner like a flood. Coloured by carve order, the hue follows the walk itself, so you can watch where it went first. Started from the middle, the backtracker spirals off in one direction, gets stuck, backs up and heads off somewhere else, leaving bands of colour behind it.
![]() |
![]() |
| Distance from the corner | Carve order, from the centre |
Snakes
The fourth mode, walkers, isn’t a maze at all. It starts lots of separate walks, each one wandering until it gets boxed in, with the rule that two walks can never touch. Any that come out too short are thrown away. You can tune how far apart they keep, how often they carry straight on and how crowded the picture gets.
Add --snake and each walk gets smoothed into a curve and drawn as a snake: a thin tail that thickens into the body, stripes, a head with eyes, and a forked red tongue. This one has 21 of them:

Octopus stamps
octopus.py makes blocky octopuses and squid that look as if they were printed with a rubber stamp. Everything is built on a square grid:
- The head is a block of tiles with rounded top corners, and the eyes are rings split into quarters.
- Each of the eight tentacles is a random walk of tiles. It mostly heads downwards, bends with quarter-circle elbows, and near the end it’s nudged into curling round into a hook.
- Tentacles keep a tile’s gap from each other, except where one crosses straight over another, which gets an over-and-under weave.
- Three or four tentacles are pushed to the back and printed in grey, which gives it some depth.
Squid get a pointed mantle, fins and two long tentacles with clubs on the end. Then a noise pass roughens the edges and knocks white specks out of the ink, so it looks hand-stamped rather than drawn.
![]() |
![]() |
| An octopus | A symmetric squid |
It can also print a contact sheet, with the seed counting up for each one:

LEGO squid
Then I wondered what it would look like built from LEGO. lego_squid.py borrows the creature generator from octopus.py and turns it into a mosaic of plates on a baseplate, seen from above:
- Every grid tile becomes a 2×2 patch of studs.
- Tentacle bends and the corners of an octopus’s head use quarter-circle Plate Round Corner 2×2 pieces, so they curve properly.
- Tentacle tips end in a round 2×2 plate, and squid clubs and the rings round the eyes are round 4×4 plates.
- Each eye is a white round 2×2 with a black round 1×1 pupil.
- Tentacles at the back are a darker shade of the body colour, and a few accent studs are scattered over the head.
- The rest is filled with ordinary rectangular plates, from 1×1 up to 2×8, by a greedy packer that tries the biggest plate that fits first.
![]() |
![]() |
| Orange squid, 48×48 baseplate | Lavender octopus, 32×32 baseplate |
It picks the smallest standard baseplate it fits on, and prints a parts list with BrickLink part numbers, so in principle you could order the pieces and build it. The orange squid is 79 pieces, 20 of them round corners:
saved lego_squid.png (seed 12, Orange, 48x48 baseplate)
79 pieces:
2 x Plate Round 1 x 1 4073 Black
1 x Plate 1 x 1 3024 Dark Orange
...
3 x Plate Round 4 x 4 with Hole 60474 Orange
13 x Plate Round Corner 2 x 2 7904 Orange
2 x Plate Round 2 x 2 4032 White
2 x Plate 1 x 1 3024 YellowThere are seven colour schemes, and --parts saves the list as a CSV.
Trying it yourself
Everything is in the repo, and the README lists all the options. The new scripts only need Pillow and NumPy:
git clone https://github.com/alastairhm/fractals
cd fractals
python3 -m venv python/.venv
source python/.venv/bin/activate
pip install -r python/requirements.txt
python mazes/maze_walk.py --seed 3 --colour distance
python mazes/maze_walk.py --algo walkers --snake --colour gradient -c 16 --wall 4 -o snakes.png
python octopus/octopus.py --sheet 3x3 --cell 30 -o sheet.png
python octopus/lego_squid.py --seed 12 --colour orange --parts parts.csv




