For the snow scene we may be unfamiliar, we still use VB to make a scene of snow it. In fact, the production of such a snow scene is not complicated, it is the principle of the first in the background of the black screen randomly draw a lot of white spots (snowflakes), and then make these snowflakes continue to move downward (redraw), repeated cycle, the successful simulation of the snow scene. Here is the small program, you can modify some of the data to adjust the density of snowflakes and snowflakes falling speed.
Double-click the form to write the following code:
Dim Snow (1000, 2), 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) = ten + (RND * 20)
Next J
Do as 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)-ten): Coloury = + Coloury
PSet (OLDX, Oldy), QBColor (0)
PSet (Snow (i, 0), Snow (I, 1)), RGB (Coloury, Coloury, Coloury)
Next I
Next LS
Loop
End
End Sub
Write the mouse down code for the form:
Private Sub Form_mousedown (Button as integer,shift as Integer, X as single, Y as single)
Unload Me
End Sub
Run the small program above, you can see the snow in the sky slowly falling, the ground will also have snow! Mouse Click to end the program.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.