08-16-2022, 02:12 PM
Ever code anything with a poor recollection of how it's been done before?
Well this is what you get.
Bad Life.
Play with the variables and you are getting a whole different set of results.
Well this is what you get.
Bad Life.
Play with the variables and you are getting a whole different set of results.
Code: (Select All)
'bad life
'by James D. Jarvis
'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
maxx = 600 'screen x
maxy = 500 'screen y
agelimit = 8 'the oldest a cell can be, any positivetve value, you want it higher than weaklim
growthboost = 2 'how much a cell grows each cycle
weaklim = 5 'the point at which cells are too weak to go on
merger = 1.71 ' the factor for merging cells some of the largest differences come from changing this value, any value except 0 will work
logic = 9 ' 0 to 9
pointer = 1 '1 to 3 , 1 is the only sensible one
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)
biglooplimit = (maxx + maxy) * 10
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
_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)