Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleDraw simulated snow
DescriptionThis example shows how to Draw simulated snow in Visual Basic 6.
Keywordssnow, screen saver
CategoriesGraphics
 
Thanks to Peter Chamberlin.

This program animates a bunch of white dots "falling" down the screen. It starts by randomly generating a bunch of points. It then moves them down the screen.

Each point is represented by three values. The first two are its X and Y coordinates on the screen. The third is a distance back into the screen. The farther away the point is, the darker its color and the slower it falls. This gives a very nice illusion of depth.

This program is quite relaxing to watch and would make a good screen saver.

 
Private Snow(1000, 2) As Integer
Private Amounty As Integer

Private Sub Form_Load()
    Form1.Show
    DoEvents
    Randomize
    Amounty = 325
    For J = 1 To Amounty
        Snow(J, 0) = Int(Rnd * Form1.Width)
        Snow(J, 1) = Int(Rnd * Form1.Height)
        Snow(J, 2) = 10 + (Rnd * 20)
    Next J
    
    Do While Not (DoEvents = 0)
        For LS = 1 To 10
            For I = 1 To Amounty
                OldX = Snow(I, 0)
                OldY = Snow(I, 1)
                Snow(I, 1) = Snow(I, 1) + Snow(I, 2)
                If Snow(I, 1) > Form1.Height Then
                    Snow(I, 1) = 0
                    Snow(I, 2) = 5 + (Rnd * 30)
                    Snow(I, 0) = Int(Rnd * Form1.Width)
                    OldX = 0
                    OldY = 0
                End If
                Coloury = 8 * (Snow(I, 2) - 10)
                Coloury = 60 + Coloury
                PSet (OldX, OldY), QBColor(0)
                PSet (Snow(I, 0), Snow(I, 1)), RGB(Coloury, _
                    Coloury, Coloury)
            Next I
        Next LS
        Label1.Refresh
    Loop
    End
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated