## Introduction: The Beauty of Math - Conway's Game of Life Art

I've never been in good relationship with math. Especially with high school math. I don't think I'm alone with this problem, am I right? :)

But I cannot deny the importance of mathematics, and when I have the opportunity, I use its results shamelessly. The same is in this article where I decided to present you an attempt to visualize some art created by math and simulated on an Arduino Pro Mini microcontroller module. For this I used a game created by a Cambridge mathematician, John Conway. It's about Conway’s Game of Life.

The first appearance of this concept was in an article by Martin Gardner in the Scientific American (october 1970) - MATHEMATICAL GAMES - The fantastic combinations of John Conway's new solitaire game "life". It is not a game in the strict sense of the word but it is a so-called cellular automaton, a mathematical structure, an observer creates the start structure and follows the structure evolution without any further intervention. This kind of mathematical structures began to be researched since the 1940's when the concept was invented by von Neumann, but only with the appearance of the article in the Scientific American this concept came to the public's attention.

Since then, more and more discoveries have been made in this field, more and more research, and if you search the Internet, you will be completely spoiled when you will see the latest findings in this field of mathematical research. Moreover... WIth this “game” you can simulate complex biological, chemical, social processes… and this cellular automaton can also have applications in computing and cryptography. Insane!

Ok ok

As I have told you, since I don't have too much affinity with math, it is too high for me but I want to show you that math can be beautiful. With a 16x16 RGB LED display available, I'll try to visualize the artificial world from Conway's Game of Life and other ''Life Like" worlds.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?

Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: What Is the Game?

Let's see, first of all, what this game is.

Everything happens in a two-dimensional grid of squares where we start from randomly arranged squares (** cells**). There may be more or less cells. Each cell can have more or fewer neighbors either horizontally or vertically or on the two diagonals, maximum eight neighbors, as in the picture below.

The following move, state, generation, is established according to three simple rules (in the images there are only some examples not every possible configuration):

If a cell is dead (non-existent on the grid) and has exactly 3 neighbors it will become alive (* birth*);

If the cell has 2 or 3 neighbors it will live on (it will ** survive**);

In all other cases: less than 2 neighbors (loneliness) or more than three neighbors (overcrowding) the cell will * die* (will disappear from the grid);

Of course the rules apply at the same time to all cells of a certain generation (before any of the rules are applied). This rule is thus written B3/S23 (birth at 3 neighbors, survival at 2 and 3 neighbors) We will see later that there are many other interesting worlds with other rules.

## Step 2: Software

For the software implementation I have adapted Jason Coon’s code, you can find it here on github.

For displaying color effects I used a few color palettes from cpt_city.

After the initialization of some variables and a "cell" class that stores the properties of the 256 possible cells, there are some functions I used in the program:

- random initialization of the generation Zero -
*randomFillWorld;* - calculation of the number of neighbors for a cell in the grid -
**neighbors;** - calculation of the order number of the RGB LED in the display matrix -
**XY;** - random choice of a new color palette -
**chooseNewPalette;** - in the setup function, the random number generator and the display are initialized
- in the loop function every 256 iterations, the display is deleted, a new generation is initialized, a new color palette is displayed, the cells of generation 0 are displayed, the calculations for the new generation are made, these calculations are saved, and the cycle is resumed.

I have uploaded the source code to github, I hope you will not have problems using it. Some observations:

- I could not used Jason Coon’s original code due to the memory limitations of the Arduino Pro Mini module, the original code is for teensy 3.1;
- The rules for calculating the new generation of cells can be changed and the color effects in this way can be drastically changed; Also some initial variables (
,*density*) can be changed, other color palettes can be used and the color effects will be different in this way also;*fading_step* - The display I used is quite small, with a 32x32 pixel display for example, the effects can be much more interesting, of course with another microcontroller (maybe ESP32), with a web control interface, so this project can even become a real art object, a point of attraction of a working or living space :)

## Step 3: Hardware

The electronic components used are: an Arduino Pro Mini module, four 8x8 RGB WS2812 arrays and a 5v 1A power supply. The electronic scheme is very simple, you can see it above in the first diagram.

If you decide to increase the number of RGB arrays, say to 16 ( ie a 32x32 pixel display) then you should use a microcontroller module with larger RAM (an Arduino Mega or ESP12) and also a larger power supply: 2.5 - 3A. The RGB LED matrices could be arranged as shown in the second diagram above.

All this electronics can be mounted in a box as in my instructable about chess on the arduino. An interesting plus can be brought if you slightly move away the display from the smoked plexiglas sheet and the paper piece, the LED light will become more blurred and the effect of the changing color patterns will be more organic, more natural, you can see this in the video materials at the next step. In the photos below you can see the Arduino Chess Master display used for this demo :)

*Wooden photo frame, smoked plexiglas, piece of paper, plastic frame (10mm height) for moving away the electronic board from the display (as in the second photo).*

## Step 4: Conclusions

After uploading the software you can play with the birth and survival rules. There are theoretically 2^{18} = 262144 possible Life-like rules, only some of them was studied extensively, many rules are still waiting to be discovered :) These rules can have different notations. I will use the so called Golly/RLE format where the rules are in the form Bx/Sy. The x number next to B ("Born") means how many neighbors are needed for a cell to become (or remain) alive, the y number next to S ("Survive") means how many neighbors are needed for a cell to survive in the next generation. So Conway's Game of Life notation would be in this case B3/S23. From Mirek Wojtowicz Cellular Automata explorer's site I choose seven other rules beside Conway's basic rule, in the source code on github you can see how I coded these rules in the software (simply uncomment the new rule and comment the previous rule used to experiment with them).

Finally you can look at the video materials bellow to see how everything works (turn on closed captions for info).

*Non blurred display, four rules*

** Same rules, but blurred display** (with the electronic board mounted away from the displays plexiglas sheet)

*Blurred, four other rules*

First Prize in the

Made with Math Contest

## 6 Discussions

3 months ago

I HAD FORGOTTEN ABOUT CONWAY'S GAME.. I USED TO HAVE IT FOR PC... THANKS FOR SHARING!...

Reply 3 months ago

Thanks. I'm glad I was helpful :)

3 months ago

LOVE THE WS2812 LEDS, I MADE ALSO A 225 LED SCREEN 15X15 SIZE.

AND THE PATTERNS LOOK STUNNING, LOOK,

SOME VIDEO,

AND THIS USING GLEDIATOR SOFWARE BUT I ALSO USE IT WIRELESS BY SD CARD SHIELD ON THE UNO,

WANNADUINO FROM WANNADIY

Reply 3 months ago

Hi. Thank's for sharing your projects. They are wonderful! I'm also big fun of these addressable RGB LED's. If you look at my projects here on Instructables you can find a chess game board, a lamp and a word clock made with this LED's :)

3 months ago

I've never been good with math either, but this looks like it's fun to watch!

Reply 3 months ago

Thank you!