09-11-2024, 01:36 AM
Since everyone is playing around with balls, globes, coins, circles and tigers and bears -- Oh my!! I decided to share this old Lightning Globe that I'd wrote sometime back in the stone ages of QB64. Maybe Dav, or someone skilled with the SOUND command will go in and add a nice little zappy zappy sizzle for us.
Just click on the screen and watch the lightning globe make lightning!
Just click on the screen and watch the lightning globe make lightning!
Code: (Select All)
Screen _NewImage(640, 480, 32)
Dim Kolor As _Unsigned Long
Const LevelOfVariance = 5 'Change this value to have fun with the strength of the "draw" to target.
Do
_Limit 60
Cls
Circle (320, 240), 20, &HFFAAAAAA
Paint (320, 240), &HFFAAAAAA
While _MouseInput: Wend
If _MouseButton(1) Then
StartX = 320: StartY = 240: EndX = _MouseX: EndY = _MouseY
Kolor = &HFF000000 + Int(Rnd * &H1000000)
Color Kolor
Do Until StartX = EndX And StartY = EndY
CoinToss = Rnd * 100 'The strength of "draw" which pulls the lightning to the target.
If CoinToss < LevelOfVariance Then 'Higher values meander less and go directly to the target.
XChange = Sgn(EndX - StartX) '-1,0,1, drawn always towards the mouse
YChange = Sgn(EndY - StartY)
Else
XChange = Int(Rnd * 3) - 1 '-1, 0, or 1, drawn in a random direction to let the lightning wander
YChange = Int(Rnd * 3) - 1
End If
StartX = StartX + XChange
StartY = StartY + YChange
PSet (StartX, StartY), Kolor
Loop
End If
_Display
Loop