BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Starfield simulation"
, by thechange
Using Rect and color variation.
Code
; Just another starfield simulation. ; Although this one really knocked my socks off. ; Make sure that StarMax isn't above what your CPU can handle :P ; ; I hope you like this as much as I do :)) Const ScreenWidth = 1280 Const ScreenHeight = 1024 Const StarMax = 60000 Const StarSpeed# = 0.7 Const StarDepth# = 1200 Const StarFactor# = 2 Dim sx#( StarMax ) Dim sy#( StarMax ) Dim sz#( StarMax ) Dim sr%( StarMax ) ; Red Dim sg%( StarMax ) ; Green Dim sb%( StarMax ) ; Blue SeedRnd MilliSecs() Graphics ScreenWidth , ScreenHeight For Counter = 1 To StarMax sx( Counter ) = Rnd ( -( ScreenWidth * StarFactor ) , ( ScreenWidth * StarFactor ) ) Shl 8 sy( Counter ) = Rnd ( -( ScreenHeight * StarFactor ) , ( ScreenHeight * StarFactor ) ) Shl 8 sz( Counter ) = Rnd ( StarSpeed , StarDepth ) sr( Counter ) = 255 sg( Counter ) = 255 sb( Counter ) = 255 Select Rand ( 2 ) Case 0 ; Blue sr( Counter ) = 192 + Rnd ( 63 ) Case 1 ; Purple sg( Counter ) = 224 + Rnd ( 31 ) Case 2 ; Yellow sb( Counter ) = 224 + Rnd ( 31 ) End Select Next SetBuffer BackBuffer() Repeat For Counter = 1 To StarMax sz( Counter ) = sz( Counter ) - StarSpeed If sz( Counter ) <= StarSpeed sz( Counter ) = StarDepth - 1 sx( Counter ) = Rnd ( -( ScreenWidth * StarFactor ) , ( ScreenWidth * StarFactor ) ) Shl 8 sy( Counter ) = Rnd ( -( ScreenHeight * StarFactor ) , ( ScreenHeight * StarFactor ) ) Shl 8 End If sx( 0 ) = sx( Counter ) / sz( Counter ) + ScreenWidth / 2 sy( 0 ) = sy( Counter ) / sz( Counter ) + ScreenHeight / 2 If sx( 0 ) >= 0 And sx( 0 ) < ScreenWidth And sy( 0 ) >= 0 And sy( 0 ) < ScreenHeight Grey = ( StarDepth - sz( Counter ) ) * 255 / StarDepth Red = sr( Counter ) * Grey / 255 Green = sg( Counter ) * Grey / 255 Blue = sb( Counter ) * Grey / 255 Color Red , Green , Blue Size = ( ( StarDepth - sz( Counter ) ) / 500 ) ^ 1.67 ; Alternative ;Size = ( ( StarDepth - sz( Counter ) ) / 500 ) ^ 2 + 1 ; Real ;Size = ( ( StarDepth - sz( Counter ) ) / 333 ) + 1 ; Blunt ;Size = ( ( StarDepth - sz( Counter ) ) / 666 + 1 ) * 2 ; Fluffy HalfSize = Size / 2 Rect sx( 0 ) - HalfSize , sy( 0 ) - HalfSize , Size , Size End If Next Flip Cls For Key = 1 To 255 If KeyHit ( Key ) Done = True Exit End If Next For Button = 1 To 3 If MouseHit ( Button ) Done = True Exit End If Next Until Done End
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations