_TITLE "Quick Life trans for QB64 11-06.82 2017-11-11by bplus" ' From: quick life.bas SmallBASIC (not MS) B+ G7 stripped down to favorite setting
'
' To: the one out there who has checked out Conway's Life the last couple of days.
' For you, a working version (albeit highly modified) of Conway's Life code in QB64.
'
' Quote Rules (from Wiki):
' The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells,
' each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated".
' Every cell interacts with its eight neighbours, which are the cells that are horizontally,
' vertically, or diagonally adjacent. At each step in time, the following transitions occur:
' 1) Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
' 2) Any live cell with two or three live neighbours lives on to the next generation.
' 3) Any live cell with more than three live neighbours dies, as if by overpopulation.
' 4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
' 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—births and deaths occur simultaneously, and the discrete moment at which this happens is
' sometimes called a tick (in other words, each generation is a pure function of the preceding one).
' The rules continue to be applied repeatedly to create further generations.
' (End Quote)
' Alas in practical applications we do not have infinite board to play Life, so at boundries rules
' break down as neighbor counts are only 5 max on edge and only 3 max at corners.
'This code is very easy to modify into other tests / demos:
' Try coloring by neighbor counts.
' Try other rules besides Classic 2,3 neighbors = survive, 3 neighbors = birth.
' Try regenration along the borders every other generation, which causes symetric beauties!
' Change an = the number of cells per side, even amounts that divide 700 (pixels per board side) work best.
'DEFINT A-Z
DIM qb&
(15) 'thanks Andy Amaya for use with his sub qColor fore, back qb&
(0) = _RGB(0, 0, 0) ' blackqb&
(1) = _RGB(0, 0, 128) ' blueqb&
(2) = _RGB(8, 128, 8) ' greenqb&
(3) = _RGB(0, 128, 128) ' cyanqb&
(4) = _RGB(128, 0, 0) ' redqb&
(5) = _RGB(128, 0, 128) ' magentaqb&
(6) = _RGB(128, 64, 32) ' brownqb&
(7) = _RGB(168, 168, 168) ' whiteqb&
(8) = _RGB(128, 128, 128) ' greyqb&
(9) = _RGB(84, 84, 252) ' light blueqb&
(10) = _RGB(42, 252, 42) ' light greenqb&
(11) = _RGB(0, 220, 220) ' light cyanqb&
(12) = _RGB(255, 0, 0) ' light redqb&
(13) = _RGB(255, 84, 255) ' light magentaqb&
(14) = _RGB(255, 255, 0) ' yellowqb&
(15) = _RGB(255, 255, 255) 'bright white
'test colors
'FOR i = 0 TO 15
' PRINT i,
' LINE (100, 100)-(500, 500), qb&(i), BF
' _LIMIT 1
'NEXT
an
= 70: s
= INT(ymax
/ an
): bigBlock
= an
* s: g
= 0
'seed for Conway's Life Classic
' a(x, y) = INT(RND * 2) 'for random mess
'for symmetric line
IF y
= an
/ 2 OR y
= an
/ 2 + 1 THEN a
(x
, y
) = 1
' Mandala Life regeneration of Mandala like arrays, seeds every other generation along edges
'IF g MOD 2 = 0 THEN
'FOR x = 1 TO an
' a(x, 1) = 1: a(x, an) = 1: a(1, x) = 1: a(an, x) = 1
'NEXT
'END IF
pc = a(x - 1, y - 1) + a(x - 1, y) + a(x - 1, y + 1) + a(x, y - 1) + a(x, y + 1) + a(x + 1, y - 1) + a(x + 1, y) + a(x + 1, y + 1)
ls(x, y) = pc
IF a
(x
, y
) THEN 'cell is alive so what is surviveRule
'Bplus favorite Mandala Life Rules for survival and birth
'IF INSTR("2346", r$) THEN ng(x, y) = 1 ELSE ng(x, y) = 0
'Classic Conway's Life Rules
'Bplus favorite Mandala Life Rules for survival and birth
'IF INSTR("34", r$) THEN ng(x, y) = 1 ELSE ng(x, y) = 0
'Classic Conway's Life Rules
'Bplus favorite Mandala Life Rules for survival and birth
'LINE (1, 1)-(bigBlock, bigBlock), qb&(0), BF
'Classic Conway's Life Rules
LINE (1, 1)-(bigBlock
, bigBlock
), qb&
(1), BF
IF a
(x
, y
) THEN 'show old a with it's neighbor counts br yellow or black
'Bplus favorite Mandala Life Rules for survival and birth
'LINE ((x - 1) * s + 1, (y - 1) * s + 1)-STEP(s, s), qb&(0), BF
'this separates into individual cells for Classic look
LINE ((x
- 1) * s
+ 1, (y
- 1) * s
+ 1)-STEP(s
- 2, s
- 2), qb&
(15), BF
'Mandala Life coloring by neighbor counts
'ELSE
' lc = ls(x, y)
' SELECT CASE lc
' CASE 0: cl = 15 ' br white
' CASE 1: cl = 11 ' cyan
' CASE 2: cl = 7 ' low white, br gray
' CASE 3: cl = 10 ' light green
' CASE 4: cl = 9 ' blue
' CASE 5: cl = 13 ' violet
' CASE 6: cl = 12 ' br red
' CASE 7: cl = 4 ' dark red
' CASE 8: cl = 0 ' black
' END SELECT
' LINE ((x - 1) * s + 1, (y - 1) * s + 1)-STEP(s, s), qb&(cl), BF
a(x, y) = ng(x, y) 'load a() with next generation data
g = g + 1