Sunday, July 26, 2026

Game of Life: colour, seeds, references

A Gosper gun which is formed from 2 queen bee shuttles back to back. The debris from the bee hive sparks creates a glider every cycle of 30 generations.

The Conway life appspot site has an extensive pattern library, with hundreds of interesting seeds, which are run with changing colours.

I couldn’t figure out how to do the changing colours so I asked on Stack Exchange and within hours had received a solution. It turns out that the changing colours at the Conway appspot site are based on the age of the cells:

  • green: new cells
  • yellow: one generation old
  • orange: two generations old
  • red: three generations old

The code below shows how and includes the Gosper gun seed.

I found an article by Paul Rendell about how to make a Turing Machine in the Cellular Automaton Conway’s Game of Life!

I also found a lexicon which explains all Game of Life terminology as well as many patterns with grids.

I spent some time making some of the patterns used to make the Turing Machine but eventually gave up because it was too much for me. By the way you can watch videos of the GOL Turing Machine here.

Golly is an open source, cross-platform application for exploring Conway's Game of Life and many other types of cellular automata: John von Neumann's 29-state CA, Wolfram's 1D rules, WireWorld, Generations, Paterson's Worms, Larger than Life, etc.

CODE, just with comments about the colour update (for full comments see previous post)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.colors import ListedColormap

N = 80 # array size
universe = np.zeros((N, N), dtype = int)

s= N//2 - 20 

# Gosper glider gun
universe[s, s+24] = 1
universe[s+1,[s+22,s+24]] = 1
universe[s+2,[s+12,s+13,s+20,s+21,s+34,s+35]] = 1
universe[s+3,[s+11,s+15,s+20,s+21,s+34,s+35]] = 1
universe[s+4,[s+0,s+1,s+10,s+16,s+20,s+21]] = 1
universe[s+5,[s+0, s+1, s+10,s+14,s+16,s+17,s+22,s+24]] = 1
universe[s+6,[s+10,s+16,s+24]] = 1
universe[s+7,[s+11,s+15]] = 1
universe[s+8,[s+12,s+13]] = 1

generations = 0
# initalise age
age = np.zeros(universe.shape)
colors = ['white', 'green', 'yellow', 'orange', 'red']
discrete_cmap = ListedColormap(colors)

def animate(frame, universe, img):
    global generations, age
    new_u = np.zeros((N, N), dtype = int)

    universe[0,:] = universe[-1,:] = universe[:,0] = universe[:,-1] = 0
    new_u[1:-1,1:-1] = (universe[ :-2, :-2] + universe[ :-2,1:-1] + universe[ :-2,2:] +
                        universe[1:-1, :-2]                + universe[1:-1,2:] +
                        universe[2:  , :-2] + universe[2:  ,1:-1] + universe[2:  ,2:])

    birth = (new_u==3)[1:-1,1:-1] & (universe[1:-1,1:-1]==0)
    survive = ((new_u==2) | (new_u==3))[1:-1,1:-1] & (universe[1:-1,1:-1]==1)
    universe[:] = np.zeros((N, N), dtype = int)
    universe[1:-1,1:-1][birth | survive] = 1
    population = np.count_nonzero(universe)
    
    age += universe # monitor age of cells
    age *= universe # remove dead cells
    age[age>4] = 4 # cap the age at 4
    img.set_data(age)
    ax.set_xlabel('generations = {}, population = {}'.format(generations, population))
    generations += 1


fig = plt.figure(figsize=(5, 5))
ax = plt.axes()
ax.set_yticklabels([])
ax.set_xticklabels([])
img = ax.imshow(universe, vmin=0, vmax=4, cmap=discrete_cmap)
ani = FuncAnimation(fig, animate, fargs=(universe, img,),
                    frames=220, interval=200)
ani.save("gosperGliderGun_colour.gif") # save the animations as a gif
plt.show()

No comments: