OPTION _EXPLICIT 'Bplus started 2019-09-23 from Hex Minesweeper Custom Field '2019-09-25 post with original Life Rules
'2019-09-27 OK let's try some more color!
'2019-09-28 fix hexagon fills by not using PAINT
CONST cellR
= 10 ' which makes the following constant
k(0) = &HFF000000: k(1) = &HFFFFFF88: k(2) = &HFFDDDDFF: k(3) = &HFF550033: k(4) = &HFF005500: k(5) = &HFF000044: k(6) = &HFFFF0000
' note: To preserve symmetry when cells hit boundries with a symmetric seed started in middle:
' y should be odd for 1 center row
' x should be equal to or less than y
' If int(x/2 + .5) is even then the right one of two center cells is marked else the one center cell is marked
'
Xarrd = 41 ' the top left cell has been hacked to duplicate the top right cell, to preserve symmetric seeds through a run
Yarrd = 41 'y should always be odd top preserve symmetry of center symmetric seed
xmax = (Xarrd + 2) * xSpacing: ymax = (Yarrd + 2) * ySpacing
DIM SHARED b
(0 TO Xarrd
+ 1, 0 TO Yarrd
+ 1) AS cell
, ng
(0 TO Xarrd
+ 1, 0 TO Yarrd
+ 1) AS INTEGER 'oversize the board to make it easy to count
_TITLE "Hexagon Life: Left Click to Toggle Cells On/Off, Right Click to Start Run, Escape to Quit" ' set x, y for cells and mark ceter cell(s)
xoffset = .5 * xSpacing: xStop = Xarrd - 1
xoffset = 0: xStop = Xarrd
b(x, y).x = x * xSpacing + xoffset + .5 * xSpacing
b(x, y).y = y * ySpacing + .5 * ySpacing
IF x
= INT(Xarrd
/ 2 + .5) AND y
= INT(Yarrd
/ 2 + .5) THEN b
(x
, y
).L
= 1 ELSE b
(x
, y
).L
= 0 'mark middle cell showCell x, y, 7
'setup seed by toggling cells on and off
mb = 0: c = 0: r = 0
getCell c, r, mb
b(c, r).L = 1 - b(c, r).L
showCell c, r, 7
mb = 0
_TITLE "Hexagon Life: Spacebar to Restart/Reseed, Escape to Quit" 'count the neighbors
xoffset = .5 * xSpacing: xStop = Xarrd - 1
xoffset = 0: xStop = Xarrd
'2 sets of neighbors depending if x offset or not
nc = b(x, y - 1).L + b(x + 1, y - 1).L + b(x - 1, y).L
nc = nc + b(x + 1, y).L + b(x, y + 1).L + b(x + 1, y + 1).L
nc = b(x - 1, y - 1).L + b(x, y - 1).L + b(x - 1, y).L
nc = nc + b(x + 1, y).L + b(x - 1, y + 1).L + b(x, y + 1).L
'originally tested and posted( 9/25/2019) here only 2 neighbors for birth in Classic Life it takes 3
'IF (nc = 3 AND b(x, y).L = 1) OR nc = 2 THEN ng(x, y) = 1 ELSE ng(x, y) = 0
'TempodiBasic suggested this survival if 1 survival or surviaval and birth for 2 neighbors
IF (nc
= 1 AND b
(x
, y
).L
= 1) OR nc
= 2 THEN ng
(x
, y
) = 1 ELSE ng
(x
, y
) = 0
' my first test for TempodiBasic, I mistakenly ran this which is good too!
'IF (nc = 3 AND b(x, y).L = 1) OR nc = 1 THEN ng(x, y) = 1 ELSE ng(x, y) = 0
showCell x, y, nc
IF x
= Xarrd
AND y
= 1 THEN showCell
1, 1, nc
'redraw all cells so no CLS
FOR y
= 1 TO Yarrd
'transfer data from ng to b().l and show cell xStop = Xarrd - 1
xStop = Xarrd
b(x, y).L = ng(x, y)
'showCell x, y
'fix symmetry for top left corner, match x at other end for bi-lat symmetry
b(1, 1).L = b(Xarrd, 1).L
'showCell 1, 1
kh& = 0
IF b
(c
, r
).L
= 1 THEN clr
= &HFFFFFFFF ELSE clr
= &HFF000000 clr = k(kNum)
fHexH b(c, r).x, b(c, r).y, cellR, clr
hexH b(c, r).x, b(c, r).y, cellR, &HFF000000
fHexH b(c, r).x, b(c, r).y, cellR, clr
hexH b(c, r).x, b(c, r).y, cellR, &HFF440044
IF mb1
OR mb2
THEN ' get last place mouse button was down WHILE mb1
OR mb2
' wait for mouse button release as a "click" 'LOCATE 1, 1: PRINT SPACE$(50)
'LOCATE 1, 1: PRINT mx, my, .5 * xSpacing
IF ((mx
- b
(c
, r
).x
) ^ 2 + (my
- b
(c
, r
).y
) ^ 2) ^ .5 < .5 * xSpacing
THEN 'LOCATE 1, 1: PRINT SPACE$(50)
'LOCATE 1, 1: PRINT c, r
returnCol
= c: returnRow
= r:
EXIT SUB mbNum = 0 'still here then clicked wrong
'draw Hexagon Outline that can be packed Horizontally, flat edge to flat edge
polyAngle
= _PI(2) / 6: aOff
= _PI / 2 x1
= xOrigin
+ radius
* COS(polyAngle
+ aOff
) y1
= yOrigin
+ radius
* SIN(polyAngle
+ aOff
) x2
= xOrigin
+ radius
* COS(i
* polyAngle
+ aOff
) y2
= yOrigin
+ radius
* SIN(i
* polyAngle
+ aOff
) LINE (x1
, y1
)-(x2
, y2
), c
x1 = x2: y1 = y2
'draw filled Hexagon that can be packed Horizontally, flat edge to flat edge
'uses SUB fTri
polyAngle
= _PI(2) / 6: aOff
= _PI / 2 x1
= xOrigin
+ radius
* COS(polyAngle
+ aOff
) y1
= yOrigin
+ radius
* SIN(polyAngle
+ aOff
) x2
= xOrigin
+ radius
* COS(i
* polyAngle
+ aOff
) y2
= yOrigin
+ radius
* SIN(i
* polyAngle
+ aOff
) fTri xOrigin, yOrigin, x1, y1, x2, y2, c
x1 = x2: y1 = y2