Daniel Havlik
Published © CC BY-SA

Conway's Game Of Life

Game of life on 5x5 LED Matrix on a calliope mini. Starts with the "glider".

BeginnerFull instructions provided1 hour1,649
Conway's Game Of Life

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1

Story

Read more

Schematics

Conway's game of life for calliope mini

Code

Conway's game of life for calliope mini

JavaScript
let checky = 0
let checkx = 0
let living_neighbours = 0
let current_img: Image = null
let next_img: Image = null

basic.forever(() => {
    next_img = current_img
    current_img.showImage(0)
    for (let x = 0; x <= 4; x++) {
        for (let y = 0; y <= 4; y++) {
            living_neighbours = 0
            for (let check = 0; check <= 7; check++) {
                if (check == 0) {
                    checkx = x - 1
                    checky = y - 1
                } else if (check == 1) {
                    checkx = x + 1
                    checky = y + 1
                } else if (check == 2) {
                    checkx = x + 1
                    checky = y - 1
                } else if (check == 3) {
                    checkx = x - 1
                    checky = y + 1
                } else if (check == 4) {
                    checkx = x + 1
                    checky = y
                } else if (check == 5) {
                    checkx = x - 1
                    checky = y
                } else if (check == 6) {
                    checky = y + 1
                    checkx = x
                } else if (check == 7) {
                    checky = y - 1
                    checkx = x
                }
                if (checkx < 0) {
                    checkx = 4
                } else if (checkx > 4) {
                    checkx = 0
                }
                if (checky < 0) {
                    checky = 4
                } else if (checky > 4) {
                    checky = 0
                }
                if (led.point(checkx, checky)) {
                    living_neighbours += 1
                }
            }
            if (led.point(x, y)) {
                if (living_neighbours < 2) {
                    next_img.setPixel(x, y, false)
                } else if (living_neighbours > 3) {
                    next_img.setPixel(x, y, false)
                }
            } else {
                if (living_neighbours == 3) {
                    next_img.setPixel(x, y, true)
                }
            }
        }
    }
})
current_img = images.createImage(`
    . # . . .
    . . # . .
    # # # . .
    . . . . .
    . . . . .
    `)
next_img = current_img

Credits

Daniel Havlik

Daniel Havlik

5 projects • 5 followers
Hacker, Maker, Tinkerer at Eigenbaukombinat Halle e.V., Software Engineer, Python Developer, Owner at gocept gmbh & co. kg.

Comments