+Do\r
+\r
+ ' Calculate the camera's rotation and position offsets\r
+ frameCount = frameCount + 1\r
+ cameraRotation = (3.1412 / 2) + Sin(frameCount / 35) / 100 + Sin(frameCount / 21) / 100\r
+ rs1 = Sin(cameraRotation)\r
+ rc1 = Cos(cameraRotation)\r
+\r
+ ' Update and draw each star\r
+ For starIndex = 1 To totalStars\r
+ x = starXPositions(starIndex)\r
+ y = starYPositions(starIndex)\r
+ z = starZPositions(starIndex)\r
+\r
+ ' Project the star's 3D position onto the 2D screen\r
+ projectedX = (x / z) * 160 + 160\r
+ projectedY = (y / z) * 100 + 100\r
+ PSet (projectedX, projectedY), 0 ' Erase the previous position\r
+\r
+ ' Rotate the star's position around the camera\r
+ x5 = x * rs1 - y * rc1\r
+ y5 = x * rc1 + y * rs1\r
+\r
+ ' Update the star's position with camera movement\r
+ x = x5 + Sin(frameCount / 21) * 3\r
+ y = y5 + Sin(frameCount / 18) * 3\r
+\r
+ ' Move the star closer to the viewer and wrap around if too close\r
+ z = z - 3\r
+ If z < 10 Then\r
+ z = Rnd * 300 + 400\r
+ x = Rnd * 800 - 400\r
+ y = Rnd * 800 - 400\r
+ End If\r
+\r
+ ' Project the new position and draw with perspective-based brightness\r
+ projectedX = (x / z) * 160 + 160\r
+ projectedY = (y / z) * 100 + 100\r
+ colorCode = 3000 / z + 15\r
+ If colorCode > 31 Then colorCode = 31\r
+ PSet (projectedX, projectedY), colorCode\r
+\r
+ ' Update the star's array positions\r
+ starXPositions(starIndex) = x\r
+ starYPositions(starIndex) = y\r
+ starZPositions(starIndex) = z\r
+ Next starIndex\r
+\r
+ ' Add new stars to the galaxy if needed\r
+ If maxStars - totalStars > Rnd * 800 + 100 Then CreateGalaxy: totalStars = totalStars + 1\r
+\r
+ ' Remove the two farthest stars and replace them with new ones\r
+ For a = 1 To 2\r
+ starIndex = Int(Rnd * (totalStars - 10)) + 1\r
+ Swap starXPositions(totalStars), starXPositions(starIndex)\r
+ Swap starYPositions(totalStars), starYPositions(starIndex)\r
+ Swap starZPositions(totalStars), starZPositions(starIndex)\r
+\r
+ x = starXPositions(totalStars)\r
+ y = starYPositions(totalStars)\r
+ z = starZPositions(totalStars)\r
+ projectedX = (x / z) * 160 + 160\r
+ projectedY = (y / z) * 100 + 100\r
+ PSet (projectedX, projectedY), 0 ' Erase the star\r
+ totalStars = totalStars - 1\r
+ Next a\r