Here I use one of the new sprite commands 'ZoomSprite()', it works great!
This might be ok for a screen saver if I knew how to make one.
Code: Select all
; BlackHole - BasicallyPure
; 7.5.2013
; PureBasic 5.20 beta <--- YOU NEED THIS
EnableExplicit
#PIx2 = #PI * 2
#Stars = 250
#BlackHoleSpeed = 12 ; larger = slower
Declare Error(message$)
ExamineDesktops()
Define.i dw = DesktopWidth(0), xMid = dw / 2
Define.i dh = DesktopHeight(0), yMid = dh / 2
Define.i dd = DesktopDepth(0)
Define.i a, r, g, b, z, sprite, spriteColor, frameCount
Define.f angle, BH_angle = #PI
Define.i xRadius = dw / 3
Define.i yRadius = dh / 3
Structure starType
x.f
y.f
speed.f
nSprite.i
EndStructure
Define blackHole.Point
blackHole\x = xMid - xRadius
blackHole\y = yMid
Dim star.starType(#Stars)
For a = 0 To #Stars
star(a)\x = Random(dw - 1)
star(a)\y = Random(dh - 1)
star(a)\nSprite = Random(13)
star(a)\speed = star(a)\nSprite / 2.0 + 1
Next
If InitSprite() And InitKeyboard() And OpenScreen(dw, dh, dd, "Black Hole")
Else : Error("Failed To 'InitSprite/InitKeyboard/OpenScreen'")
EndIf
For sprite = 0 To 13
r = Random(255) : b = Random(255) : g = 255 - (r + b) >> 1
spriteColor = RGB(r, g, b)
If CreateSprite(sprite, 16, 16) = 0 : Error("CreateSprite") : EndIf
StartDrawing(SpriteOutput(sprite))
Circle(7, 7, 3, spriteColor)
LineXY(0, 7, 14, 7, spriteColor)
LineXY(7, 0, 7, 14, spriteColor)
StopDrawing()
z = 6 + sprite * 2
ZoomSprite(sprite, z, z) ; <-- does not belong inside start/stop drawing block!
Next sprite
Repeat ; animation loop
ClearScreen(#Black)
;StartDrawing(ScreenOutput()) ; <--- don't need this!
For a = 0 To #Stars
With star(a)
angle = ATan2(blackHole\x - \x, blackHole\y - \y)
\x + \speed * Cos(angle)
\y + \speed * Sin(angle)
If Abs(\x - blackHole\x) < 5 And Abs(\y - blackHole\y) < 5
Select Random(4, 1)
Case 1 : \x = Random(dw - 1) : \y = 0
Case 2 : \x = Random(dw - 1) : \y = dh - 1
Case 3 : \x = 0 : \y = Random(dh - 1)
Case 4 : \x = dw - 1 : \y = Random(dh - 1)
EndSelect
EndIf
DisplayTransparentSprite(\nSprite,\x,\y)
EndWith
Next
If frameCount < #BlackHoleSpeed : frameCount + 1
Else : frameCount = 0
BH_angle + Radian(1)
If BH_angle > #PIx2 : BH_angle - #PIx2 : EndIf
blackHole\x = Cos(BH_angle) * xRadius + xMid
blackHole\y = Sin(BH_angle) * yRadius + yMid
EndIf
;StopDrawing()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape) : End : EndIf
ForEver
Procedure Error(message$)
MessageRequester("Fatal Error!", message$) : End
EndProcedure