Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bad Life
#2
I modified this program to try to prevent repeated tedious compilation for changing one value.
Now at the command line, provide the name of a text file which has settings.
Because this program reads the whole graphics screen, there isn't an easy way to speed up the iterations.

Code: (Select All)
'bad life
'by James D. Jarvis
''QB64 phoenix forums, modified by mnrvovrfc gc16
'I was knocking out a quick version of life seeded by mouse doodles and something went wrong
'eventually the program mutated into what you see now
'change the values and what emerges will vary

dim ff as long, kount as integer, biglooplimit as long, dolimitorig as _byte, value as single

a$ = command$(1)
if a$ = "" then
    print "Please give the name of a text file at the command line."
    end
end if
if not _fileexists(a$) then
    print "File not found: "; a$
    end
end if

kount = 0
ff = freefile
open a$ for input as ff
do until eof(ff)
    line input #ff, b$
    if not (b$ = "" or left$(b$, 1) = "'") then
        kount = kount + 1
        if kount > 9 then exit do
        select case kount
            case 1
                value = val(b$)
                if value < 320 or value > 1280 then maxx = 600 else maxx = int(value)
            case 2
                value = val(b$)
                if value < 200 or value > 768 then maxy = 500 else maxy = int(value)
            case 3
                value = val(b$)
                if value > 0 then agelimit = int(value) else agelimit = 8
            case 4
                value = val(b$)
                if value > 0 then growthboost = int(value) else growthboost = 2
            case 5
                value = val(b$)
                if value > 0 then weaklim = int(value) else weaklim = 5
            case 6
                value = val(b$)
                if value > 0 then merger = value else merger = 1.71
            case 7
                value = val(b$)
                if value >= 0 and value < 10 then logic = int(value) else logic = 9
            case 8
                value = val(b$)
                if value > 0 and value < 4 then pointer = int(value) else pointer = 1
            case 9
                value = val(b$)
                if value > 10 and value <= 1e+6 then biglooplimit = int(value) else biglooplimit = 0
        end select
    end if
loop
close ff


Screen _NewImage(maxx, maxy, 256)
_Title "Bad Life"
Dim cell(0 To maxx - 1, 0 To maxy - 1)
Dim ncell(0 To maxx - 1, 0 To maxy - 1)

if biglooplimit = 0 then
    dolimitorig = 1
    biglooplimit = (maxx + maxy) * 10
end if
For x = 1 To maxx - 1
    For y = 1 To maxy - 1
        cell(x, y) = 0
    Next y
Next x
Print "Bad Life"
Print "Doodle on the screen with the mouse. Press any key when ready."
'you can keep placing points later in the program but it doesn't wait for you
Do
    _Limit 60
    Do While _MouseInput

        x = _MouseX
        y = _MouseY
        'check for the mouse pointer in the image drawing area

        If _MouseButton(1) Then
            PSet (x, y), 1
            cell(x, y) = 4
            If pointer > 1 Then
                Select Case pointer
                    Case 2
                        For px = x - 1 To x + 1
                            For py = y - 1 To y + 1
                                cell(px, py) = cell(px, py) + 4
                                PSet (px, py), cell(px, py)
                            Next py
                        Next px
                    Case 3
                        For px = x - 2 To x + 2
                            For py = y - 2 To y + 2
                                cell(px, py) = cell(px, py) + Int((Abs(px) + Abs(py)) / 2)
                                PSet (px, py), cell(px, py)
                            Next py
                        Next px


                End Select
            End If
        End If
    Loop
    a$ = InKey$
Loop Until a$ <> ""

g = 0
Do

    Cls
    if dolimitorig then _Limit 60
    For x = 2 To maxx - 2
        _Limit biglooplimit
        For y = 2 To maxy - 2
            ncell(x, y) = 0
            If logic > -1 Then
                If cell(x - 1, y) > 0 Then ncell(x, y) = Int((cell(x - 1, y) + cell(x, y)) / merger) + growthboost
                If cell(x + 1, y) > 0 Then ncell(x, y) = Int((cell(x + 1, y) + cell(x, y)) / merger) + growthboost
                If cell(x, y - 1) > 0 Then ncell(x, y) = Int((cell(x, y - 1) + cell(x, y)) / merger) + growthboost
                If cell(x, y + 1) > 0 Then ncell(x, y) = Int((cell(x, y + 1) + cell(x, y)) / merger) + growthboost
            End If
            If logic > 0 Then If cell(x, y) > 0 Then ncell(x, y) = cell(x, y) + growthboost
            If logic > 1 Then
                If cell(x - 1, y - 1) > 0 Then ncell(x, y) = Int((cell(x - 1, y - 1) + cell(x, y)) / merger) + growthboost
                If cell(x - 1, y + 1) > 0 Then ncell(x, y) = Int((cell(x - 1, y + 1) + cell(x, y)) / merger) + growthboost
                If cell(x + 1, y - 1) > 0 Then ncell(x, y) = Int((cell(x + 1, y - 1) + cell(x, y)) / merger) + growthboost
                If cell(x + 1, y + 1) > 0 Then ncell(x, y) = Int((cell(x + 1, y + 1) + cell(x, y)) / merger) + growthboost
            End If
            If logic > 2 Then
                If cell(x - 1, y) > 0 Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x + 1, y) > 0 Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x, y - 1) > 0 Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x, y + 1) > 0 Then ncell(x, y) = cell(x, y) + growthboost
            End If
            If logic > 3 Then
                If cell(x - 1, y - 1) > 0 Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x - 1, y + 1) > 0 Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x + 1, y - 1) > 0 Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x + 1, y + 1) > 0 Then ncell(x, y) = cell(x, y) + growthboost
            End If
            If logic > 4 Then
                If cell(x - 1, y - 1) > cell(x, y) Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x - 1, y + 1) > cell(x, y) Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x + 1, y - 1) > cell(x, y) Then ncell(x, y) = cell(x, y) + growthboost
                If cell(x + 1, y + 1) > cell(x, y) Then ncell(x, y) = cell(x, y) + growthboost
            End If
            If logic > 5 Then
                If cell(x - 1, y) > cell(x, y) / 2 Then ncell(x, y) = Int((cell(x - 1, y) + cell(x, y)) / merger) + growthboost
                If cell(x + 1, y) > cell(x, y) / 2 Then ncell(x, y) = Int((cell(x + 1, y) + cell(x, y)) / merger) + growthboost
                If cell(x, y - 1) > cell(x, y) / 2 Then ncell(x, y) = Int((cell(x, y - 1) + cell(x, y)) / merger) + growthboost
                If cell(x, y + 1) > cell(x, y) / 2 Then ncell(x, y) = Int((cell(x, y + 1) + cell(x, y)) / merger) + growthboost
            End If
            If logic > 7 Then
                If cell(x - 1, y - 1) > 0 Then ncell(x, y) = Int((cell(x - 1, y - 1) + ncell(x, y)) / merger) + growthboost
                If cell(x - 1, y + 1) > 0 Then ncell(x, y) = Int((cell(x - 1, y + 1) + ncell(x, y)) / merger) + growthboost
                If cell(x + 1, y - 1) > 0 Then ncell(x, y) = Int((cell(x + 1, y - 1) + ncell(x, y)) / merger) + growthboost
                If cell(x + 1, y + 1) > 0 Then ncell(x, y) = Int((cell(x + 1, y + 1) + ncell(x, y)) / merger) + growthboost
            End If
            If logic > 8 Then
                If cell(x - 1, y) > cell(x, y) / 2 Then ncell(x, y) = 0
                If cell(x + 1, y) > cell(x, y) / 2 Then ncell(x, y) = 0
                If cell(x, y - 1) > cell(x, y) / 2 Then ncell(x, y) = 0
                If cell(x, y + 1) > cell(x, y) / 2 Then ncell(x, y) = 0
            End If


        Next y
    Next x
    For y = 2 To maxy - 2
        _Limit biglooplimit
        For x = 2 To maxx - 2

            cell(x, y) = ncell(x, y)
            If cell(x, y) > agelimit Or cell(x, y) < weaklim Then cell(x, y) = 0
            PSet (x, y), cell(x, y)

        Next x
    Next y

    Locate 1, 1: Print g
    _Display
    g = g + 1
    If B$ = "m" Then merger = merger + 1
    If B$ = "n" Then
        merger = merger - 1
        If merger = 0 Then merger = -1
    End If
    If B$ = "," Then
        weaklim = weaklim - 1
        If weaklim < 1 Then weaklim = 1
    End If
    If B$ = "." Then
        weaklim = weaklim + 1
        If weaklim > agelimit - 1 Then weaklim = agelimit - 1
    End If

    If B$ = "a" Then agelimit = agelimit + 1
    If B$ = "z" Then
        agelimit = agelimit - 1
        If agelimit < wealim + growth Then agelimit = wealim + growth
    End If
    If B$ = "g" Then growthboost = growthboost + 1
    If B$ = "f" Then
        growthboost = growthboost - 1
        If growthboost < 1 Then growthboost = 1
    End If

    If B$ = "l" Then
        logic = logic + 1
        If logic > 9 Then logic = 0
    End If

    B$ = InKey$
    Do While _MouseInput

        x = _MouseX
        y = _MouseY
        'check for the mouse pointer in the image drawing area

        If _MouseButton(1) Then
            PSet (x, y), 1
            cell(x, y) = 4
            If pointer > 1 Then
                Select Case pointer
                    Case 2
                        For px = x - 1 To x + 1
                            For py = y - 1 To y + 1
                                If px > 1 And py > 1 And px < maxx - 1 And py < maxy - 1 Then
                                    cell(px, py) = cell(px, py) + 4
                                    PSet (px, py), cell(px, py)
                                End If
                            Next py
                        Next px
                    Case 3
                        For px = x - 2 To x + 2
                            For py = y - 2 To y + 2
                                If px > 2 And py > 2 And px < maxx - 2 And py < maxy - 2 Then
                                    cell(px, py) = cell(px, py) + Int((Abs(px) + Abs(py)) / 2)
                                    PSet (px, py), cell(px, py)
                                End If
                            Next py
                        Next px
                    Case 4
                        For px = x - 1 To x + 1
                            For py = y - 1 To y + 1
                                cell(px, py) = 0
                                PSet (px, py), 0
                            Next py
                        Next px


                End Select
            End If

        End If
    Loop


Loop Until B$ = Chr$(27)

Now will require this file (edit as you want):
Code: (Select All)
'screen x
600
'screen y
500
'the oldest a cell can be, any positive value, you want it higher than weaklim
8
'how much a cell grows each cycle
2
'the point at which cells are too weak to go on
5
' the factor for merging cells some of the largest differences come from changing this value, any value except 0 will work
1.71
' 0 to 9
9
'1 to 3, 1 is the only sensible one
1
'"biglooplimit", up to a million, set to zero so it behaves like original program, set as slow as ten to go to sleep LOL
50000
Reply


Messages In This Thread
Bad Life - by James D Jarvis - 08-16-2022, 02:12 PM
RE: Bad Life - by mnrvovrfc - 08-16-2022, 03:07 PM
RE: Bad Life - by James D Jarvis - 08-16-2022, 05:58 PM



Users browsing this thread: 1 Guest(s)