Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (January 2021)
Reason: unfinished
Document.png Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (January 2021)

Wikipedia-logo.svg  For more information, see Conway's Game of Life on Wikipedia.

An example of the game

Conway's Game of Life is a simulation of an infinite world of 'live' and 'dead' square cells.

The rules will first be explained, and then one can either try and code their own project, or carry on reading and try to recreate the example script.

The Rules

Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, also called a tick, the following transitions occur all at once:

  1. Any live cell with two or three neighbors survives (stays blue).
  2. Any dead (white) cell with three live neighbors becomes a live cell.
  3. All other cells die in the next generation. Similarly, all other dead cells stay dead.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed. The rules continue to be applied repeatedly to created further generations.

How to create it

How to draw a single cell

The following is the script to draw a single square cell. It will be used in the rendering of the game.

define cell x(x) y(y) size(size) state(state)
if <(state) = [alive]> then
set pen color to (#fbfbfb)
set pen color to (#000000)
set pen size to (size)
go to x(x) y(y)
pen down
pen up
if <(size) > (2)> then
set pen size to ((size)/(3))
go to x((size)+((size)/(-2))) y((size)+((size)/(-2)))
pen down
go to x((size)+((size)/(2))) y((size)+((size)/(-2)))
go to x((size)+((size)/(2))) y((size)+((size)/(2)))
go to x((size)+((size)/(-2))) y((size)+((size)/(2)))
go to x((size)+((size)/(-2))) y((size)+((size)/(-2)))
pen up

Rendering Script

First, set the variables

(Stage width)
(stage height)

Then, one should make a custom block defined as the following:

define render
erase all
set (# v) to (1)
set (x v) to (-240)
set (y v) to (-180)
repeat (Stage height)
repeat (Stage width)
draw cell x(x) y(y) size((360)/(Stage height)) status (item (#) of (pixel values v)):: custom
change (x v) by ((480)/(Stage width))
change (# v) by (1)
set (x v) to (-240)
change (y v) by ((360)/(Stage height))


A setup block should be created and defined as the following. One has to check the "Run without screen refresh" checkbox for this to work as it should.

define setup
delete all of (pixel values v)
repeat ((Stage width)*(Stage height))
add (dead) to (pixel values v)

Then, one should add the final script:

when green flag clicked
set (Stage height v) to (72)
set (Stage width v) to (96)
setup:: custom
update:: custom
render:: custom

See also