by A Kubacki (2 Submissions)
Category: Graphics
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)
3d starfield
Assumes
all you need is a timer control, and a back background for the form
Code Returns
stars!!!
Side Effects
extreme obsessiong with putting this on every platform possible, calculators, etc...
Dim X(1000) As Integer
Dim Y(1000) As Integer
Dim z(1000) As Integer
Dim xv(1000) As Long
Dim yv(1000) As Long
Dim sss As Long
Dim numstarz As Integer
Dim colora As Long
Dim i, j, k, m As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Form1.Hide
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1
Form1.Show
numstarz = 250
Form1.Enabled = True
init
End Sub
Private Sub init()
For i = 1 To numstarz
X(i) = Rnd() * 1000 - 500
Y(i) = Rnd() * 1000 - 500
z(i) = 1 + Rnd() * 256
Next i
End Sub
Private Sub drawptz()
Dim asdf As Integer
sss = 40 * ScaleWidth / 1000
For k = 1 To numstarz
xv(k) = X(k) * 3 * sss / ((z(k)))
yv(k) = Y(k) * 3 * sss / ((z(k)))
Next k
For j = 1 To numstarz
z(j) = z(j) - 1
If z(j) < 40 Then
z(j) = 200 + Rnd() * 40
End If
Next j
For i = 1 To numstarz
asdf = 256 - z(i)
colora = RGB(asdf, asdf, asdf)
PSet (xv(i) + ScaleWidth / 2, yv(i) + ScaleHeight / 2), colora
Next i
End Sub
Private Sub Timer1_Timer()
Form1.Enabled = True
Timer1.Enabled = True
For m = 1 To 10
Cls
drawptz
Next m
End Sub