Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Glow Bug
#1
Ever since I saw B+ and others make these, I've always wanted to try and make something like this myself. So I finally did today, without any help! Well besides Steve's fill-in circles. 
But going back even further to the 80's, I've tried for countless times to make the math of this and never could figure it out, until today! Big Grin 

Thanks B+ and others for the inspiration! 

Feel free to use the code for anything you want. This is just a glow bug example, to quit press Esc. 

Code: (Select All)

_Title "Glow Bug - by SierraKen"

Screen _NewImage(800, 600, 32)

Randomize Timer
oldx = 400
oldy = 300
Do

    bugs xx, yy, oldx, oldy


Loop Until InKey$ = Chr$(27)


Sub bugs (xx, yy, oldx, oldy)
    Do
        If d1 > d2 Then s = s + .1
        If d2 > d1 Then s = s - .1
        d = d + 1
        If d > t Then
            oldx = oldx + x
            oldy = oldy + y
            morebugs d1, d2, d, t
        End If
        x = Cos(s * _Pi / 180) * d
        y = Sin(s * _Pi / 180) * d
        xx = x + oldx
        yy = y + oldy
        If xx > 750 Then oldx = 50: Cls: morebugs d1, d2, d, t
        If xx < 50 Then oldx = 750: Cls: morebugs d1, d2, d, t
        If yy > 550 Then oldy = 50: Cls: morebugs d1, d2, d, t
        If yy < 50 Then oldy = 550: Cls: morebugs d1, d2, d, t
        fillCircle xx, yy, 10, _RGB32(255, 255, 0)
        _Delay .001
        Line (0, 0)-(800, 600), _RGB32(0, 0, 0, 10), BF
        _Display
    Loop Until InKey$ = Chr$(27)
    End
End Sub

Sub morebugs (d1, d2, d, t)
    d1 = Rnd * 360
    d2 = Rnd * 360
    d = 0
    t = Int(Rnd * 360) + 1
End Sub


'from Steve Gold standard
Sub fillCircle (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub
Reply


Messages In This Thread
Glow Bug - by SierraKen - 7 hours ago
RE: Glow Bug - by SierraKen - 6 hours ago
RE: Glow Bug - by SierraKen - 6 hours ago
RE: Glow Bug - by SMcNeill - 5 hours ago
RE: Glow Bug - by bplus - 4 hours ago
RE: Glow Bug - by SierraKen - 2 hours ago



Users browsing this thread: 5 Guest(s)