Petri Dish
#1
This is an improvement on a program I posted a couple days ago.  It'll get a some more development at some point. 

The screen is randomly populated with an assortment of microbes. They'll skitter about but they do become tired and bored. If you click the mouse that will excite them and get their attention. You can also adjust the temperature and see how they endure. New microbes will slowly spawn in if the population drops.

The program will end when there are no surviving microbes. 

Code: (Select All)
'petri_dish
'By James D Jarvis
'
' bunch of wandering microbes   in a perti dish
'click on the screen with the left mouse button or drag the mouse around the screen holding hte button down and the ...
'microbes will become more excited and move towards the clicks
'control the temperature with the < and > keys

Dim Shared xmax, ymax
xmax = 1100
ymax = 600
Screen _NewImage(xmax, ymax, 32)
_Title "petri dish"
Randomize Timer
ncells = 20 + Int(Rnd * 100) '<- chnage this as desired
Dim Shared X(ncells), Y(ncells), r(ncells), xv(ncells), yv(ncells), kkr(ncells), kkg(ncells), kkb(ncells), a(ncells)
Dim Shared rt(ncells), lstn(ncells), tmp, cold(ncells), hot(ncells), health(ncells)
'build the cells
For c = 1 To ncells
    X(c) = Int(2 + Rnd * (xmax - 60) / 28) * 30
    Y(c) = Int(2 + Rnd * (ymax - 60) / 28) * 30
    r(c) = 4 + Int(Rnd * 6)
    xv(c) = Int(2 - Rnd * 4)
    yv(c) = Int(2 - Rnd * 4)
    kkr(c) = 150 + Int(Rnd * 100)
    kkg(c) = 150 + Int(Rnd * 100)
    kkb(c) = 150 + Int(Rnd * 100)
    a(c) = 2 + Int(Rnd * 16)
    rt(c) = Int(Rnd * 4) - Int(Rnd * 4)
    lstn(c) = Int(Rnd * 100)
    cold(c) = Int(Rnd * 10) - 5
    hot(c) = Int(Rnd * 30) + Abs(cold(c)) + 15
    health(c) = 100 + Int(Rnd * 100)
Next c
tmp = 20
taptap = 0

Do
    headcount = 0
    Cls
    Locate 1, 1: Print tmp; "ø"
    While _MouseInput
        mouseLeftButton = _MouseButton(1)

        If mouseLeftButton Then
            taptap = taptap + 50
            tapx = _MouseX
            tapy = _MouseY
        End If
    Wend
    _Limit 30
    For c = 1 To ncells

        If health(c) > 0 Then
            headcount = headcount + 1
            draw_microbe X(c), Y(c), r(c), kkr(c), kkg(c), kkb(c), a(c), c

            If Rnd * 10 < 7 Then X(c) = X(c) + xv(c)
            If Rnd * 10 < 7 Then Y(c) = Y(c) + yv(c)
            If yv(c) > 30 Then yv(c) = 27
            If xv(c) > 30 Then xv(c) = 27

            If Rnd * 10 < 3 Then xv(c) = xv(c) * .95
            If Rnd * 10 < 3 Then yv(c) = yv(c) * .95
            If taptap > lstn(c) And tapy < Y(c) Then yv(c) = yv(c) - .5
            If taptap > lstn(c) And tapy > Y(c) Then yv(c) = yv(c) + .5
            If taptap > lstn(c) And tapx < X(c) Then xv(c) = xv(c) - .5
            If taptap > lstn(c) And tapx > X(c) Then xv(c) = xv(c) + .5
            If tatap > 0 And X(c) = tapx And Y(x) = tapy Then health(c) = health(c) + 1


            If X(c) < r(c) * 2 Then xv(c) = xv(c) * -1
            If Y(c) < r(c) * 2 Then yv(c) = yv(c) * -1
            If X(c) > xmax - r(c) * 2 Then xv(c) = xv(c) * -1
            If Y(c) > ymax - r(c) * 2 Then yv(c) = yv(c) * -1

            If tmp < cold(c) Then
                xv(c) = xv(c) * .9
                health(c) = health(c) - 1
                If health(c) < 100 Then kkb(c) = kkb(c) + 1
            End If
            If tmp > hot(c) * .75 And tmp < hot(c) * 1.2 Then
                xv(c) = xv(c) * 1.01
                health(c) = health(c) + 1

            End If
            If tmp > hot(c) * 1.2 Then
                xv(c) = xv(c) * .9
                health(c) = health(c) - 1
                If health(c) < 100 Then kkr(c) = kkr(c) + 1
                If kkr(c) > 255 Then kkr(c) = 255
            End If

        End If
        If health(c) > 200 Then health(c) = 200
        If health(c) = 0 And Rnd * 400 < 10 And temp > cold(c) Then
            X(c) = Int(2 + Rnd * (xmax - 60) / 28) * 30
            Y(c) = Int(2 + Rnd * (ymax - 60) / 28) * 30
            r(c) = 4 + Int(Rnd * 6)
            xv(c) = Int(2 - Rnd * 4)
            yv(c) = Int(2 - Rnd * 4)
            kkr(c) = 150 + Int(Rnd * 100)
            kkg(c) = 150 + Int(Rnd * 100)
            kkb(c) = 150 + Int(Rnd * 100)
            a(c) = 2 + Int(Rnd * 16)
            rt(c) = Int(Rnd * 4) - Int(Rnd * 4)
            lstn(c) = Int(Rnd * 100)
            cold(c) = temp * .35
            hot(c) = temp + 50
            health(c) = 100 + Int(Rnd * 100)
            headcount = headcount + 1
        End If
    Next c
    _Display
    If taptap > 1 Then taptap = taptap - 1
    kk$ = InKey$
    If kk$ = "," Or kk$ = "<" Then tmp = tmp - .1
    If kk$ = "." Or kk$ = ">" Then tmp = tmp + .1
    If headcount = 0 Then
        Locate 5, 5: Print "ALL MICROBES DIED"
        kk$ = Chr$(27)
    End If

Loop Until kk$ = Chr$(27)

Input "PRESS ENER TO continue", any$

Sub draw_microbe (x, y, r, kR, kG, kB, arm, c)
    'draw a crude radial microbe with flagellum
    Draw "C" + Str$(_RGB32(kR, kG, kB))
    If x > xmax - r(c) * 2 Then x = xmax - r(c) * 2
    If y > ymax - r(c) * 2 Then y = ymax - r(c) * 2
    If x < r(c) * 2 Then x = r(c) * 2
    If y < r(c) * 2 Then y = r(c) * 2

    Draw "bm" + Str$(x) + "," + Str$(y)
    rv = Rnd * .2
    For ang = 0 + rt(c) To 360 + rt(c) Step Int(360 / arm) + rv
        wiggle$ = " r" + Str$((r + Int(Rnd * 3)) * .33) + " e" + Str$(1 + Int(Rnd * r(c) / 6))
        wiggle$ = wiggle$ + " r" + Str$((r + Int(Rnd * 3)) * .33) + " e" + Str$(1 + Int(Rnd * r(c) / 6))
        wiggle$ = wiggle$ + " r" + Str$((r + Int(Rnd * 3)) * .33)
        Draw "ta" + Str$(ang) + wiggle$ + "bm" + Str$(x) + "," + Str$(y)
        ' Draw "ta" + Str$(ang) + " r" + Str$(r + Int(Rnd * 3)) + " u" + Str$(1 + Int(Rnd * 3)) + "m" + Str$(x) + "," + Str$(y)
    Next ang

End Sub
Reply
#2
Pretty cool! Reminds me of something someone did back in the old forum about bacteria or something populating at an increasing speed. But I think that was just dots and not little designs like yours.
Reply
#3
Eventually going to slap in some nutrient solution and a more variability in behavior.
Reply




Users browsing this thread: 1 Guest(s)