Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Life
#1
Information 
Just tried to program the game of "Life" by John Conway (1970)

Fun project so far!

Code: (Select All)
'The game of Life
'Based on the 1970 game by John Conway

'James2464 Aug 2022

Screen _NewImage(1650, 1000, 32)
_ScreenMove 0, 0
Randomize Timer

$Resize:Off

Const pi = 3.1415926


Const xblack = _RGB32(0, 0, 0)
Const xwhite = _RGB32(255, 255, 255)
Const xred = _RGB32(255, 0, 0)
Const xgreen = _RGB32(125, 255, 125)
Const xblue = _RGB32(0, 0, 255)
Const xyellow = _RGB32(150, 125, 0)
Const xpink = _RGB32(255, 0, 255)
Const xcyan = _RGB32(0, 255, 255)
Const xbrown = _RGB32(80, 0, 0)
Const xdarkgreen = _RGB32(0, 128, 0)
Const xlightgray = _RGB32(110, 110, 110)
Const xdarkgray = _RGB32(10, 10, 10)


Dim c1#(100)
c1#(0) = xblack
c1#(1) = xwhite
c1#(2) = xred
c1#(3) = xgreen
c1#(4) = xblue
c1#(5) = xyellow
c1#(6) = xpink
c1#(7) = xcyan
c1#(8) = xbrown
c1#(9) = xdarkgreen
c1#(10) = xlightgray
c1#(11) = xdarkgray




'================================================================================================================
'================================================================================================================
'================================================================================================================


'INITIALIZE

Cls
Dim mn(1000, 800)
Dim dp(1000, 800)
Dim aj(1000, 800)

'grid size
gx = 400
gy = 235
'resolution (1=smallest)
res1 = 4

Cls
xtxt = 60

Locate 10, xtxt
Print "Select starting pattern"
Locate 11, xtxt
Print "1.  Full screen random scatter"
Locate 12, xtxt
Print "2.  Fixed pattern A"
Locate 13, xtxt
Print "3.  Random pattern partial"
Locate 14, xtxt
Print "4.  Manually draw using mouse pointer.  Left click when finished."
Locate 15, xtxt
Print "5.  Fixed pattern B"
Locate 20, xtxt
Input "Choose 1-5: ", start1

'start1 = 5


'=================== random full
If start1 = 1 Then
    For j = 1 To gx
        For k = 1 To gy
            r = Int(Rnd * 10)
            If r < 3 Then
                mn(j, k) = 1
            Else
                mn(j, k) = 0
            End If
        Next k
    Next j
End If

'=============================== fixed pattern
If start1 = 2 Then
    gx = 400
    gy = 235
    res1 = 4



    For j = 105 To 300 Step 12
        For k = 80 To 160
            mn(j, k) = 1
        Next k
    Next j
    For j = 1 To gx
        For k = 1 To gy
            If mn(j, k) <> 1 Then
                mn(j, k) = 0
            End If
        Next k
    Next j
End If


'=============================== random partial
If start1 = 3 Then
    For j = 1 To gx
        For k = 1 To gy
            mn(j, k) = 0
        Next k
    Next j

    For j = 40 To gx Step 1
        tt = Int(gy / 2)
        t = Int(Rnd * tt) + 40
        For k = 10 To t
            mn(j, k) = 1
        Next k
    Next j
End If

'================================draw with mouse pointer
If start1 = 4 Then

    'use mouse to draw starting pattern

    'draw STARTING GRID
    For j = 1 To gx
        For k = 1 To gy
            Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1#(mn(j, k)), BF
        Next k
    Next j
    Do

        Do While _MouseInput
        Loop
        x% = _MouseX
        y% = _MouseY
        'Locate 1, 1
        'Print x%, y%
        x1 = Int(x% / res1)
        y1 = Int(y% / res1)
        mn(x1, y1) = 1
        'mn(x1 - 1, y1 - 1) = 1
        'mn(x1 + 1, y1 - 1) = 1
        'mn(x1 + 1, y1 + 1) = 1
        'mn(x1, y1 + 1) = 1
        'mn(x1 + 1, y1) = 1
        'mn(x1, y1 - 1) = 1
        'draw  GRID
        For j = 1 To gx
            For k = 1 To gy
                Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1#(mn(j, k)), BF
            Next k
        Next j

        lc% = _MouseButton(1)
    Loop Until lc% = -1
End If



'=============================== fixed pattern - lines
If start1 = 5 Then

    For k = 110 To gy - 80 Step 25
        For j = 80 To gx - 80
            mn(j, k) = 1
        Next j
    Next k
End If








'================================================================================================================
'================================================================================================================
'================================================================================================================


Cls
Locate 10, xtxt
Print "Press space bar to show starting pattern."
Locate 15, xtxt
Print "Then press space bar again to start algorithm."
Locate 16, xtxt
Print "While running, press 't' to toggle to thermal cam view."

Do While InKey$ = ""
Loop

'draw STARTING GRID
For j = 1 To gx
    For k = 1 To gy
        Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1#(mn(j, k)), BF
    Next k
Next j

Do While InKey$ = ""
Loop


'================================================================================================================
'================================================================================================================
'================================================================================================================





flag1 = 0

Do While flag1 = 0

    'BEGIN

    'COPY ARRAY

    For j = 1 To gx
        For k = 1 To gy
            dp(j, k) = mn(j, k)
        Next k
    Next j



    '================ SCAN FIRST ROW =============================


    'top left corner
    aj(1, 1) = dp(1, 2) + dp(2, 1) + dp(2, 2)



    'main portion of top row
    For j = 2 To gx - 1
        aj(j, 1) = dp(j - 1, 1) + dp(j + 1, 1) + dp(j - 1, 2) + dp(j, 2) + dp(j + 1, 2)
    Next j



    'top right corner
    aj(gx, 1) = dp(gx - 1, 1) + dp(gx - 1, 2) + dp(gx, 2)



    '=============SCAN SECOND TO SECOND LAST ROW=================

    For k = 2 To gy - 1

        'scan first position only
        aj(1, k) = dp(1, k - 1) + dp(2, k - 1) + dp(2, k) + dp(2, k + 1) + dp(1, k + 1)

        'scan main portion of current row
        For j = 2 To gx - 1
            aj(j, k) = dp(j - 1, k - 1) + dp(j, k - 1) + dp(j + 1, k - 1) + dp(j - 1, k) + dp(j + 1, k) + dp(j - 1, k + 1) + dp(j, k + 1) + dp(j + 1, k + 1)
        Next j

        'scan end position only
        aj(gx, k) = dp(gx, k - 1) + dp(gx - 1, k - 1) + dp(gx - 1, k) + dp(gx - 1, k + 1) + dp(gx, k + 1)

    Next k




    '======================SCAN LAST ROW=======================



    'bottom left corner
    aj(1, gy) = dp(1, gy - 1) + dp(2, gy - 1) + dp(2, gy)



    'main portion of last row
    For j = 2 To gx - 1
        aj(j, gy) = dp(j - 1, gy) + dp(j + 1, gy) + dp(j - 1, gy - 1) + dp(j, gy - 1) + dp(j + 1, gy - 1)
    Next j



    'bottom right corner
    aj(gx, gy) = dp(gx - 1, gy) + dp(gx - 1, gy - 1) + dp(gx, gy - 1)




    '=======================APPLY RULES AND UPDATE GRID========================

    'rule 1 - if cell was dead and had exactly 3 neighbours, it becomes alive
    'rule 2 - if cell was alive and had <2 or >3 neighbours, it becomes dead

    For k = 1 To gy
        For j = 1 To gx
            If dp(j, k) = 0 Then
                If aj(j, k) = 3 Then
                    mn(j, k) = 1
                End If
            End If
            If dp(j, k) = 1 Then
                If aj(j, k) < 2 Or aj(j, k) > 3 Then
                    mn(j, k) = 0
                End If
            End If
        Next j
    Next k

    '=======================DRAW NEW UPDATED GRID=============================
    For j = 1 To gx
        For k = 1 To gy
            If tog1 = 0 Then
                Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1#(mn(j, k)), BF
            Else
                Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1#(aj(j, k)), BF
            End If
        Next k
    Next j




    If InKey$ = "t" Then tog1 = tog1 + 1
    If InKey$ = "x" Then flag1 = 1

    If tog1 > 1 Then tog1 = 0
Loop
Reply
#2
Oh, this brings back memories... not standing in line... the game... lol...

Thank you, James.
May your journey be free of incident. Live long and prosper.
Reply
#3
Works a lot better than the last one I tried to make. Good job.
Reply
#4
One of the challenges of Conway's "Game" of Life is to find initial starting patterns that do not die out. Making Life Immortal!
b = b + ...
Reply
#5
(08-13-2022, 04:46 PM)bplus Wrote: One of the challenges of Conway's "Game" of Life is to find initial starting patterns that do not die out. Making Life Immortal!

I only know about this "game" from watching this video recently:

https://youtu.be/HeQX2HjkcNo

(It's mentioned in this video that a few patterns keep growing forever) 

And I thought it would be fun to program this and see how it really behaves.   Being able to create interesting starting patterns is important, and so far I have just a crude few options.   Maybe some day it'll be better, we'll see.   If anyone here wants to expand on that, please do.
Reply
#6
Wow that video covers allot! And Pete be glad to know that math is Not Perfect, so they say, a hole?

Anyway been a fan of Conway's Life since early 90's with GW Basic. Use to write a variation with every new PL update.

Here is a favorite if you like colorful symmetric patterns that seem endless, Mandala Life:
Code: (Select All)
_Title "Mandala Life trans for QB64 11-06.82  2017-11-11 by 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.

Const xmax = 700
Const ymax = 700

Screen _NewImage(xmax, ymax, 32)
_ScreenMove 360, 20

'DEFINT A-Z
Dim qb&(15) 'thanks Andy Amaya for use with his sub qColor fore, back
qb&(0) = _RGB(0, 0, 0) '       black
qb&(1) = _RGB(0, 0, 128) '     blue
qb&(2) = _RGB(8, 128, 8) '     green
qb&(3) = _RGB(0, 128, 128) '   cyan
qb&(4) = _RGB(128, 0, 0) '     red
qb&(5) = _RGB(128, 0, 128) '   magenta
qb&(6) = _RGB(128, 64, 32) '   brown
qb&(7) = _RGB(168, 168, 168) ' white
qb&(8) = _RGB(128, 128, 128) ' grey
qb&(9) = _RGB(84, 84, 252) '   light blue
qb&(10) = _RGB(42, 252, 42) '  light green
qb&(11) = _RGB(0, 220, 220) '  light cyan
qb&(12) = _RGB(255, 0, 0) '    light red
qb&(13) = _RGB(255, 84, 255) ' light magenta
qb&(14) = _RGB(255, 255, 0) '  yellow
qb&(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 = 140: s = Int(ymax / an): bigBlock = an * s: g = 0
Dim a(1 To an, 1 To an), ng(1 To an, 1 To an), ls(1 To an, 1 To an)

'seed for Conway's Life Classic
'FOR y = 2 TO an - 1
'    FOR x = 2 TO an - 1

'        ' 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

'    NEXT
'NEXT

While InKey$ <> " "

    ' 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

    For x = 2 To an - 1
        For y = 2 To an - 1
            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
            r$ = Right$(Str$(pc), 1)
            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
                'IF INSTR("23", r$) THEN ng(x, y) = 1 ELSE ng(x, y) = 0

            Else 'birth?

                '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
                'IF INSTR("3", r$) THEN ng(x, y) = 1 ELSE ng(x, y) = 0
            End If
        Next
    Next

    '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
    For y = 1 To an
        For x = 1 To an
            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

            End If
        Next
    Next
    _Display
    For y = 1 To an
        For x = 1 To an
            a(x, y) = ng(x, y) 'load a() with next generation data
        Next
    Next
    g = g + 1
    If g > 70 Then _Limit 1
Wend
b = b + ...
Reply
#7
(08-13-2022, 04:46 PM)bplus Wrote: One of the challenges of Conway's "Game" of Life is to find initial starting patterns that do not die out. Making Life Immortal!

Nice, but I see problems:

1) colors should be stored in unsigned longs
2) use $COLOR:32
3) inkey$ was being called multiple times
4) tight loop waiting for key could cause overheating - use _LIMIT or _SLEEP
5) arrays were being moved one element at a time - use _MEMCOPY to speed it up
6) _DISPLAY after updates are complete is nicer

Here's a version with most of the issues fixed.

Code: (Select All)
' Game of Life based on the 1970 game by John Conway, James2464 Aug 2022

Screen _NewImage(800, 600, 32)
_ScreenMove (_DesktopWidth - _Width) \ 2, 20
Randomize Timer

$Resize:Off

Const xblack = _RGB32(0, 0, 0)
Const xwhite = _RGB32(255, 255, 255)
Const xred = _RGB32(255, 0, 0)
Const xgreen = _RGB32(125, 255, 125)
Const xblue = _RGB32(0, 0, 255)
Const xyellow = _RGB32(150, 125, 0)
Const xpink = _RGB32(255, 0, 255)
Const xcyan = _RGB32(0, 255, 255)
Const xbrown = _RGB32(80, 0, 0)
Const xdarkgreen = _RGB32(0, 128, 0)
Const xlightgray = _RGB32(110, 110, 110)
Const xdarkgray = _RGB32(10, 10, 10)

Dim c1~&(100)
c1~&(0) = xblack
c1~&(1) = xwhite
c1~&(2) = xred
c1~&(3) = xgreen
c1~&(4) = xblue
c1~&(5) = xyellow
c1~&(6) = xpink
c1~&(7) = xcyan
c1~&(8) = xbrown
c1~&(9) = xdarkgreen
c1~&(10) = xlightgray
c1~&(11) = xdarkgray

'================================================================================================================
'================================================================================================================
'================================================================================================================

'INITIALIZE

Cls
Dim mn(1000, 800)
Dim dp(1000, 800)
Dim aj(1000, 800)

'grid size
gx = 400
gy = 235
'resolution (1=smallest)
res1 = 4

Cls
xtxt = 20

Locate 10, xtxt
Print "Select starting pattern"
Locate 11, xtxt
Print "1.  Full screen random scatter"
Locate 12, xtxt
Print "2.  Fixed pattern A"
Locate 13, xtxt
Print "3.  Random pattern partial"
Locate 14, xtxt
Print "4.  Manually draw using mouse pointer.  Left click when finished."
Locate 15, xtxt
Print "5.  Fixed pattern B"
Locate 20, xtxt
Input "Choose 1-5: ", start1

'start1 = 5

'=================== random full
If start1 = 1 Then
    For j = 1 To gx
        For k = 1 To gy
            r = Int(Rnd * 10)
            If r < 3 Then
                mn(j, k) = 1
            Else
                mn(j, k) = 0
            End If
        Next k
    Next j
End If

'=============================== fixed pattern
If start1 = 2 Then
    gx = 400
    gy = 235
    res1 = 4

    For j = 105 To 300 Step 12
        For k = 80 To 160
            mn(j, k) = 1
        Next k
    Next j
    For j = 1 To gx
        For k = 1 To gy
            If mn(j, k) <> 1 Then
                mn(j, k) = 0
            End If
        Next k
    Next j
End If

'=============================== random partial
If start1 = 3 Then
    For j = 1 To gx
        For k = 1 To gy
            mn(j, k) = 0
        Next k
    Next j

    For j = 40 To gx Step 1
        tt = Int(gy / 2)
        t = Int(Rnd * tt) + 40
        For k = 10 To t
            mn(j, k) = 1
        Next k
    Next j
End If

'================================draw with mouse pointer
If start1 = 4 Then

    'use mouse to draw starting pattern

    'draw STARTING GRID
    For j = 1 To gx
        For k = 1 To gy
            Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1~&(mn(j, k)), BF
        Next k
    Next j
    Do

        Do While _MouseInput
        Loop
        x% = _MouseX
        y% = _MouseY
        'Locate 1, 1
        'Print x%, y%
        x1 = Int(x% / res1)
        y1 = Int(y% / res1)
        mn(x1, y1) = 1
        'mn(x1 - 1, y1 - 1) = 1
        'mn(x1 + 1, y1 - 1) = 1
        'mn(x1 + 1, y1 + 1) = 1
        'mn(x1, y1 + 1) = 1
        'mn(x1 + 1, y1) = 1
        'mn(x1, y1 - 1) = 1
        'draw  GRID
        For j = 1 To gx
            For k = 1 To gy
                Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1~&(mn(j, k)), BF
            Next k
        Next j

        lc% = _MouseButton(1)
    Loop Until lc% = -1
End If

'=============================== fixed pattern - lines
If start1 = 5 Then

    For k = 110 To gy - 80 Step 25
        For j = 80 To gx - 80
            mn(j, k) = 1
        Next j
    Next k
End If

'================================================================================================================
'================================================================================================================
'================================================================================================================

Cls
Locate 10, xtxt
Print "Press space bar to show starting pattern."
Locate 15, xtxt
Print "Then press space bar again to start algorithm."
Locate 16, xtxt
Print "While running, press 't' to toggle to thermal cam view."

Do: _Limit 10
Loop Until Len(InKey$)

'draw STARTING GRID
For j = 1 To gx
    For k = 1 To gy
        Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1~&(mn(j, k)), BF
    Next k
Next j

Do: _Limit 10
Loop Until Len(InKey$)

'================================================================================================================
'================================================================================================================
'================================================================================================================

Dim As _MEM m0, m1
m0 = _Mem(dp(0, 0))
m1 = _Mem(mn(0, 0))

Do

    'COPY ARRAY

    'For j = 1 To gx
    '    For k = 1 To gy
    '    dp(j, k) = mn(j, k)
    'Next k
    'Next j

    _MemCopy m1, m1.OFFSET, m1.SIZE To m0, m0.OFFSET

    '================ SCAN FIRST ROW =============================

    'top left corner
    aj(1, 1) = dp(1, 2) + dp(2, 1) + dp(2, 2)

    'main portion of top row
    For j = 2 To gx - 1
        aj(j, 1) = dp(j - 1, 1) + dp(j + 1, 1) + dp(j - 1, 2) + dp(j, 2) + dp(j + 1, 2)
    Next j

    'top right corner
    aj(gx, 1) = dp(gx - 1, 1) + dp(gx - 1, 2) + dp(gx, 2)

    '=============SCAN SECOND TO SECOND LAST ROW=================

    For k = 2 To gy - 1

        'scan first position only
        aj(1, k) = dp(1, k - 1) + dp(2, k - 1) + dp(2, k) + dp(2, k + 1) + dp(1, k + 1)

        'scan main portion of current row
        For j = 2 To gx - 1
            aj(j, k) = dp(j - 1, k - 1) + dp(j, k - 1) + dp(j + 1, k - 1) + dp(j - 1, k) + dp(j + 1, k) + dp(j - 1, k + 1) + dp(j, k + 1) + dp(j + 1, k + 1)
        Next j

        'scan end position only
        aj(gx, k) = dp(gx, k - 1) + dp(gx - 1, k - 1) + dp(gx - 1, k) + dp(gx - 1, k + 1) + dp(gx, k + 1)

    Next k

    '======================SCAN LAST ROW=======================

    'bottom left corner
    aj(1, gy) = dp(1, gy - 1) + dp(2, gy - 1) + dp(2, gy)

    'main portion of last row
    For j = 2 To gx - 1
        aj(j, gy) = dp(j - 1, gy) + dp(j + 1, gy) + dp(j - 1, gy - 1) + dp(j, gy - 1) + dp(j + 1, gy - 1)
    Next j

    'bottom right corner
    aj(gx, gy) = dp(gx - 1, gy) + dp(gx - 1, gy - 1) + dp(gx, gy - 1)

    '=======================APPLY RULES AND UPDATE GRID========================

    'rule 1 - if cell was dead and had exactly 3 neighbours, it becomes alive
    'rule 2 - if cell was alive and had <2 or >3 neighbours, it becomes dead

    For k = 1 To gy
        For j = 1 To gx
            If dp(j, k) = 0 Then
                If aj(j, k) = 3 Then
                    mn(j, k) = 1
                End If
            End If
            If dp(j, k) = 1 Then
                If aj(j, k) < 2 Or aj(j, k) > 3 Then
                    mn(j, k) = 0
                End If
            End If
        Next j
    Next k

    '=======================DRAW NEW UPDATED GRID=============================
    For j = 1 To gx
        For k = 1 To gy
            If tog1 = 0 Then
                Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1~&(mn(j, k)), BF
            Else
                Line (j * res1, k * res1)-(j * res1 + res1, k * res1 + res1), c1~&(aj(j, k)), BF
            End If
        Next k
    Next j

    _Display
    i$ = InKey$
    If i$ = "t" Then tog1 = tog1 Xor 1

Loop Until i$ = "x"
Reply
#8
Thank you for the improvements! My programming is very rough...I appreciate this
Reply
#9
Even simpler and faster is to base the screen resolution and array sizes on gx, gy, and res1.
Reply
#10
(08-14-2022, 12:41 AM)ChiaPet Wrote: Even simpler and faster is to base the screen resolution and array sizes on gx, gy, and res1.

I wanted the largest array possible but my PC really slowed down noticeably when the array sizes were over 400.    Anything to speed it up would be great.
Reply




Users browsing this thread: 6 Guest(s)