by Adam Lane (3 Submissions)
Category: Graphics
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating:
(5 Votes)
This is a really cool form effect, it looks like a starfield moving from the middle of the screen out at you, it kind of looks like the Windows screen saver. This is not originally my code, but i like it so much that i have made a better version of it. You can change the speed and color of the field. This is an update of my last submission (https://www.vbcoders.com/vb/scripts/ShowCode.asp?txtCodeId=40900&lngWId=1). Enjoy
Moving StarField Form BG (3D
Version)
by Adam Lane
1) Create a form and a timer
2) Form1 and Timer1
3) Copy this code into your form
Dim X(50), Y(50), xSpeed(50), ySpeed(50) As Integer
Private Sub Form_Load()
Dim i As Integer
Timer1.Interval = 4
Form1.BackColor = vbBlack
Form1.ForeColor = vbBlack
Form1.FillColor = vbBlack
For i = 0 To 49
X(i) = -1
Y(i) = -1
Next i
Randomize
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
For i = 0 To 49
PSet (X(i), Y(i)), &H0&
If X(i) < 0 Or X(i) > Form1.ScaleWidth Or Y(i) < 0 Or Y(i) > Form1.ScaleHeight Then
X(i) = Form1.ScaleWidth \ 2
Y(i) = Form1.ScaleHeight \ 2
xSpeed(i) = Int(Rnd(1) * 200) - 100
ySpeed(i) = Int(Rnd(1) * 200) - 100
End If
X(i) = X(i) + xSpeed(i)
Y(i) = Y(i) + ySpeed(i)
PSet (X(i), Y(i)), &HFFFFFF
Next i
End Sub