Code: (Select All)
' radial flagellum cells animation
' By James D. Jarvis
' a simple simulation of animated cells
'they will bounce off the sides and wrestle with shove and pull each other now and again
' press esc to quit
xmax = 1100
ymax = 600
Screen _NewImage(xmax, ymax, 32)
_Title "Radial Flagellum"
Randomize Timer
ncells = 16+(rnd*16) 'you could also make this a fixed number, don't go too high this seems to bog down with too many cells
Dim Shared X(ncells), Y(ncells), r(ncells), xv(ncells), yv(ncells), kkr(ncells), kkg(ncells), kkb(ncells), a(ncells)
Dim Shared rt(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) = 20 + Int(Rnd * 60)
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) = 8 + Int(Rnd * 16)
rt(c) = Int(Rnd * 4) - Int(Rnd * 4)
Next c
'animate the cells
Do
_Limit 60
Cls
For c = 1 To ncells
For n = r(c) To Int(r(c) * .4) Step -2
draw_microbe X(c) + Sin(n / 4), Y(c) + Cos(n / 4), n + Int(Rnd * 4), kkr(c) - n * 2, kkg(c) - n * 2, kkb(c) - n * 2, a(c), c
Next
X(c) = X(c) + xv(c)
Y(c) = Y(c) + yv(c)
If X(c) < r(c) Then xv(c) = xv(c) * -1
If Y(c) < r(c) Then yv(c) = yv(c) * -1
If X(c) > xmax - r(c) Then xv(c) = xv(c) * -1
If Y(c) > ymax - r(c) Then yv(c) = yv(c) * -1
For c2 = 1 To ncells
If c2 <> c Then
If Int((X(c) + r(c)) / 40) = Int((X(c2) + r(c2)) / 40) And Int((Y(c) + r(c)) / 40) = Int((Y(c2) + r(c2)) / 40) Then
xv(c) = xv(c) * -1
yv(c) = yv(c) * -1
xv(c2) = xv(c2) * -1 + Rnd * .2 - Rnd * .2
yv(c2) = yv(c2) * -1 + Rnd * .2 - Rnd * .2
End If
End If
Next c2
rt(c) = rt(c) - (Rnd * 3) + (Rnd * 3)
Next
_Display
k$ = InKey$
Loop Until k$ = Chr$(27)
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))
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