article

Moving StarField Form BG (3D Version)

Email
Submitted on: 1/29/2015 10:33:00 AM
By: Adam Lane (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB 5.0, VB 6.0
Views: 509
 
     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 (http://www.planet-source-code.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


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.