; TheChange@yahoo.com
Const ScreenSizeX = 1280
Const ScreenSizeY = 1024
Const StarMax = 50000 ; You may want to cut down on the number of stars
; Speed of the stars, depth of starfield and starfactor (square radius)
; are the main visual controls.
Const StarSpeed = 100
Const StarDepth# = 1200
Const StarFactor# = 20
Const StarZoom# = 1.0333
Type Star
Field X# ; Positions
Field Y#
Field Z#
Field SpeedX# ; Velocities
Field SpeedY#
Field SpeedZ#
Field Red ; Each star has its individual color/shade
Field Green
Field Blue
End Type
SeedRnd MilliSecs()
Graphics ScreenSizeX , ScreenSizeY
; Star positions, velocities and colors are pre-generated.
Local Star.Star
Color 255 , 255 , 255
For Counter = 1 To StarMax
Star = New Star
Star\X = 0 ; All stars together at the beginning
Star\Y = 0
Star\Z = StarDepth / 2
Angle# = Rnd ( 360 ) ; Stars will move in a circular manner
Distance# = Rnd ( StarSpeed ) * StarFactor
Star\SpeedX = GetVectorX ( Distance , Angle )
Star\SpeedY = GetVectorY ( Distance , Angle )
Star\SpeedZ = Rnd ( -StarSpeed , StarSpeed )
Star\Red = 255 ; Default to white color
Star\Green = 255
Star\Blue = 255
Select Rand ( 3 ) ; 3 possible color shades
Case 1 ; Cyan
Star\Red = 191 + Rand ( 63 )
Case 2 ; Purple
Star\Green = 191 + Rand ( 63 )
Case 3 ; Yellow
Star\Blue = 191 + Rand ( 63 )
End Select
Next
Delay 1000
SetBuffer BackBuffer()
Repeat
LockBuffer
For Star = Each Star
Star\X = Star\X + Star\SpeedX ; Update positions and speed
Star\Y = Star\Y + Star\SpeedY
Star\Z = Star\Z + Star\SpeedZ / StarDepth
Star\SpeedZ = Star\SpeedZ * StarZoom
sx = Star\X / Star\Z + ScreenSizeX / 2 ; Calculate pixel on screen (centered)
sy = Star\Y / Star\Z + ScreenSizeY / 2
If sx >= 0 ; Range checking
If sx < ScreenSizeX
If sy >= 0
If sy < ScreenSizeY
Grey = ( Abs ( StarDepth - Star\Z ) * 255 / StarDepth ) Mod 256 + 128
If Grey > 255 Then Grey = 512 - Grey ; Calculate grey scale shade
Red = Star\Red * Grey / 256 ; Blend with star's color
Green = Star\Green * Grey / 256
Blue = Star\Blue * Grey / 256
RGB = GetRGB ( Red , Green , Blue )
WritePixelFast sx , sy , RGB
End If
End If
End If
End If
Next
UnlockBuffer
Flip
Cls
; The 'any' key
For Key = 1 To 255
If KeyHit ( Key )
Done = True
Exit
End If
Next
; The 'any' button
For Button = 1 To 3
If MouseHit ( Button )
Done = True
Exit
End If
Next
Until Done
End
Function GetVectorX# ( Distance# , Angle# ) ; Get horizontal size of vector using distance and angle
Return Sin ( Angle ) * Distance
End Function
Function GetVectorY# ( Distance# , Angle# ) ; Get vertical size of vector using distance and angle
Return Sin ( Angle - 90 ) * Distance
End Function
Function GetRGB% ( Red% , Green% , Blue% ) ; Combine red, green and blue color components
Return Red Shl 16 + Green Shl 8 + Blue
End Function
               (
geocities.com/thechange)