home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD2022.psc / snow.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-11-23  |  30.5 KB  |  833 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "3D Snow"
  5.    ClientHeight    =   8265
  6.    ClientLeft      =   2385
  7.    ClientTop       =   1935
  8.    ClientWidth     =   9585
  9.    ControlBox      =   0   'False
  10.    FillColor       =   &H80000003&
  11.    Icon            =   "snow.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   551
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   639
  18.    Begin VB.HScrollBar HScroll1 
  19.       Height          =   255
  20.       Left            =   3480
  21.       Max             =   20
  22.       Min             =   1
  23.       TabIndex        =   19
  24.       Top             =   7800
  25.       Value           =   1
  26.       Width           =   1695
  27.    End
  28.    Begin VB.TextBox txtAngle 
  29.       Height          =   285
  30.       Left            =   1200
  31.       TabIndex        =   17
  32.       Text            =   "3"
  33.       Top             =   7800
  34.       Width           =   615
  35.    End
  36.    Begin VB.CheckBox chkRotate 
  37.       Caption         =   "Rotating Flakes"
  38.       Height          =   255
  39.       Left            =   1920
  40.       TabIndex        =   16
  41.       Top             =   7560
  42.       Value           =   1  'Checked
  43.       Width           =   1455
  44.    End
  45.    Begin VB.CommandButton cmdFullScreen 
  46.       Caption         =   "&Full Screen"
  47.       Height          =   375
  48.       Left            =   5280
  49.       TabIndex        =   14
  50.       Top             =   7320
  51.       Width           =   2415
  52.    End
  53.    Begin VB.Timer tmrFlakeHorzRotate 
  54.       Interval        =   1000
  55.       Left            =   7680
  56.       Top             =   7320
  57.    End
  58.    Begin VB.PictureBox picSnowLarge 
  59.       Appearance      =   0  'Flat
  60.       AutoRedraw      =   -1  'True
  61.       AutoSize        =   -1  'True
  62.       BackColor       =   &H00404040&
  63.       BorderStyle     =   0  'None
  64.       ForeColor       =   &H80000008&
  65.       Height          =   435
  66.       Index           =   99
  67.       Left            =   6360
  68.       Picture         =   "snow.frx":014A
  69.       ScaleHeight     =   29
  70.       ScaleMode       =   3  'Pixel
  71.       ScaleWidth      =   58
  72.       TabIndex        =   13
  73.       Top             =   8640
  74.       Width           =   870
  75.    End
  76.    Begin VB.CommandButton cmdQuit 
  77.       Caption         =   "&Close"
  78.       Height          =   495
  79.       Left            =   8160
  80.       TabIndex        =   12
  81.       ToolTipText     =   "Press ALT-C to Quit"
  82.       Top             =   7320
  83.       Width           =   1215
  84.    End
  85.    Begin VB.CheckBox chkWrap 
  86.       Caption         =   "Wrap-around Snow"
  87.       Height          =   255
  88.       Left            =   1920
  89.       TabIndex        =   11
  90.       Top             =   8040
  91.       Value           =   1  'Checked
  92.       Visible         =   0   'False
  93.       Width           =   1695
  94.    End
  95.    Begin VB.CheckBox chkRandSpeed 
  96.       Caption         =   "Random Speed"
  97.       Height          =   255
  98.       Left            =   1920
  99.       TabIndex        =   10
  100.       Top             =   7800
  101.       Width           =   1455
  102.    End
  103.    Begin VB.CheckBox chkDots 
  104.       Caption         =   "Big Dots"
  105.       Height          =   255
  106.       Left            =   1920
  107.       TabIndex        =   9
  108.       Top             =   7320
  109.       Value           =   1  'Checked
  110.       Width           =   1335
  111.    End
  112.    Begin VB.TextBox txtDots 
  113.       Height          =   285
  114.       Left            =   1200
  115.       TabIndex        =   8
  116.       Text            =   "500"
  117.       Top             =   7560
  118.       Width           =   615
  119.    End
  120.    Begin VB.TextBox txtFlakes 
  121.       Height          =   285
  122.       Left            =   1200
  123.       TabIndex        =   5
  124.       Text            =   "50"
  125.       Top             =   7320
  126.       Width           =   615
  127.    End
  128.    Begin VB.CommandButton cmdApply 
  129.       Caption         =   "&Apply Changes"
  130.       Height          =   375
  131.       Left            =   5280
  132.       TabIndex        =   4
  133.       Top             =   7800
  134.       Width           =   2415
  135.    End
  136.    Begin VB.PictureBox Picture2 
  137.       AutoRedraw      =   -1  'True
  138.       BackColor       =   &H00000000&
  139.       Height          =   7200
  140.       Left            =   15
  141.       Picture         =   "snow.frx":157C
  142.       ScaleHeight     =   476
  143.       ScaleMode       =   3  'Pixel
  144.       ScaleWidth      =   637
  145.       TabIndex        =   3
  146.       Top             =   0
  147.       Visible         =   0   'False
  148.       Width           =   9615
  149.    End
  150.    Begin VB.PictureBox picSnowSmall 
  151.       Appearance      =   0  'Flat
  152.       AutoRedraw      =   -1  'True
  153.       AutoSize        =   -1  'True
  154.       BackColor       =   &H80000005&
  155.       BorderStyle     =   0  'None
  156.       ForeColor       =   &H80000008&
  157.       Height          =   225
  158.       Left            =   6480
  159.       Picture         =   "snow.frx":FCFF
  160.       ScaleHeight     =   15
  161.       ScaleMode       =   3  'Pixel
  162.       ScaleWidth      =   30
  163.       TabIndex        =   2
  164.       Top             =   8520
  165.       Visible         =   0   'False
  166.       Width           =   450
  167.    End
  168.    Begin VB.PictureBox picSnowLarge 
  169.       Appearance      =   0  'Flat
  170.       AutoRedraw      =   -1  'True
  171.       AutoSize        =   -1  'True
  172.       BackColor       =   &H80000005&
  173.       BorderStyle     =   0  'None
  174.       ForeColor       =   &H80000008&
  175.       Height          =   435
  176.       Index           =   0
  177.       Left            =   7320
  178.       Picture         =   "snow.frx":102A5
  179.       ScaleHeight     =   29
  180.       ScaleMode       =   3  'Pixel
  181.       ScaleWidth      =   58
  182.       TabIndex        =   1
  183.       Top             =   8640
  184.       Width           =   870
  185.    End
  186.    Begin VB.PictureBox Picture1 
  187.       AutoRedraw      =   -1  'True
  188.       BackColor       =   &H00000000&
  189.       Height          =   7200
  190.       Left            =   0
  191.       ScaleHeight     =   476
  192.       ScaleMode       =   3  'Pixel
  193.       ScaleWidth      =   637
  194.       TabIndex        =   0
  195.       Top             =   0
  196.       Width           =   9615
  197.    End
  198.    Begin VB.Label Label4 
  199.       Alignment       =   2  'Center
  200.       Caption         =   "Background:"
  201.       Height          =   255
  202.       Left            =   3480
  203.       TabIndex        =   20
  204.       Top             =   7440
  205.       Width           =   1695
  206.    End
  207.    Begin VB.Label Label3 
  208.       Caption         =   "Rotation Degr."
  209.       Height          =   255
  210.       Left            =   120
  211.       TabIndex        =   18
  212.       Top             =   7800
  213.       Width           =   1095
  214.    End
  215.    Begin VB.Label lblAngle 
  216.       Height          =   375
  217.       Left            =   5160
  218.       TabIndex        =   15
  219.       Top             =   8640
  220.       Width           =   975
  221.    End
  222.    Begin VB.Label Label2 
  223.       Caption         =   "Snow Dots"
  224.       Height          =   255
  225.       Left            =   120
  226.       TabIndex        =   7
  227.       Top             =   7560
  228.       Width           =   1095
  229.    End
  230.    Begin VB.Label Label1 
  231.       Caption         =   "Snow Flakes"
  232.       Height          =   255
  233.       Left            =   120
  234.       TabIndex        =   6
  235.       Top             =   7320
  236.       Width           =   975
  237.    End
  238. Attribute VB_Name = "Form1"
  239. Attribute VB_GlobalNameSpace = False
  240. Attribute VB_Creatable = False
  241. Attribute VB_PredeclaredId = True
  242. Attribute VB_Exposed = False
  243. 'VB Snow
  244. 'Portions from vb-world.net
  245. 'And from planet-source-code.com
  246. 'Majority of the code (either original or modified) -
  247. 'Zane Horton
  248. 'Background pictures from www.planetside.co.uk - Home of Terragen
  249. 'Thanks to the original author of Snowflakes on Planet Source Code
  250. 'From which this got started when I said, 'I wonder how fast this would
  251. 'be with Setpixel instead of Pset...'
  252. 'Set SetPixelIt to FALSE in the Sub cmdApply_Click()
  253. 'if you want to see how much of a difference it makes...
  254. 'Start array index with 1 not 0.
  255. Option Base 1
  256. Option Explicit
  257. Dim FLAKEROTATEANGLE As Integer
  258. Dim I As Integer
  259. Dim j As Integer
  260. Dim AvgFPS As Single
  261. Dim TempDBL As Double
  262. Dim NumFrames As Long
  263. Dim FullScreenSize As Boolean
  264. Dim OrgScreenX As Integer
  265. Dim OrgScreenY As Integer
  266. Dim OrgScreenBPP As Byte
  267. Dim Max_Snow As Integer
  268. Dim Max_Flakes As Integer
  269. Dim BigFlakes As Boolean
  270. Dim setPixelIt As Boolean
  271. Dim SnowWrap As Boolean
  272. Dim FullScreen As Boolean
  273. Dim RandSpeed As Boolean
  274. Dim RotatingFlakes As Boolean
  275. Dim Backgrounds(99) As String
  276. Private Type Snow
  277.     X As Integer
  278.     Y As Integer
  279.     Z As Integer
  280.     Speed As Integer
  281.     Wind As Integer
  282.     CLR As Long
  283. End Type
  284. Private Type SnowFlake
  285.     X As Long
  286.     Y As Long
  287.     Speed As Integer
  288.     Wind As Integer
  289.     LargeFlake As Boolean
  290.     LastX As Long
  291.     lastY As Long
  292.     FlakeNum As Byte
  293. End Type
  294. Dim Snow(9999) As Snow
  295. Dim SnowFlakes(9999) As SnowFlake
  296. Dim Ended As Boolean
  297. Sub DoSnow() 'Create & Animate the snow.
  298.     Dim tmr1 As New clsTimer
  299.     Dim FPS As Single
  300.     Dim NumBlts As Long
  301.     Dim NumSets As Long
  302.     Dim tempSNG As Single
  303.     tmr1.StartTimer
  304.     BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, SRCCOPY
  305.     'Picture1.Cls
  306.     For I = 1 To Max_Snow
  307.         'Allow other system events. (So it doesn't freeze)
  308.         DoEvents
  309.             'Calculate New Position
  310.             Snow(I).Y = Snow(I).Y + Snow(I).Speed
  311.             If SnowWrap Then
  312.                 If Snow(I).X > Picture1.ScaleWidth Then Snow(I).X = 0
  313.             End If
  314.             Snow(I).X = Snow(I).X + Snow(I).Wind
  315.             'Erase Old and Draw new
  316.             If setPixelIt Then
  317.                 If BigFlakes Then
  318.                     SetPixel Picture1.hdc, (Snow(I).X), (Snow(I).Y), Snow(I).CLR
  319.                     SetPixel Picture1.hdc, (Snow(I).X), (Snow(I).Y) + 1, Snow(I).CLR
  320.                     SetPixel Picture1.hdc, (Snow(I).X) + 1, (Snow(I).Y), Snow(I).CLR
  321.                     SetPixel Picture1.hdc, (Snow(I).X) + 1, (Snow(I).Y) + 1, Snow(I).CLR
  322.                   Else
  323.                     SetPixel Picture1.hdc, (Snow(I).X), (Snow(I).Y), Snow(I).CLR
  324.                 End If
  325.               Else
  326.                 If BigFlakes Then
  327.                     Picture1.PSet ((Snow(I).X), (Snow(I).Y)), Snow(I).CLR
  328.                     Picture1.PSet ((Snow(I).X), (Snow(I).Y) + 1), Snow(I).CLR
  329.                     Picture1.PSet ((Snow(I).X) + 1, (Snow(I).Y)), Snow(I).CLR
  330.                     Picture1.PSet ((Snow(I).X) + 1, (Snow(I).Y) + 1), Snow(I).CLR
  331.                   Else
  332.                     Picture1.PSet ((Snow(I).X), (Snow(I).Y)), Snow(I).CLR
  333.                 End If
  334.             End If
  335.             
  336.             'If snow is offscreen, bring it back to the top
  337.             'and give it a new X axis location.
  338.             
  339.             If Snow(I).Y > Picture1.ScaleHeight - 10 Then
  340.                 If GetPixel(Picture1.hdc, Snow(I).X + Snow(I).Wind, Snow(I).Y + Snow(I).Speed) = vbWhite Then
  341.                     If setPixelIt Then
  342.                         If BigFlakes Then
  343.                             SetPixel Picture1.hdc, (Snow(I).X + Snow(I).Wind), (Snow(I).Y + Snow(I).Speed) - 1, Snow(I).CLR
  344.                             SetPixel Picture1.hdc, (Snow(I).X + Snow(I).Wind) + 1, (Snow(I).Y + Snow(I).Speed) - 1, Snow(I).CLR
  345.                             SetPixel Picture1.hdc, (Snow(I).X + Snow(I).Wind), (Snow(I).Y + Snow(I).Speed), Snow(I).CLR
  346.                             SetPixel Picture1.hdc, (Snow(I).X + Snow(I).Wind) + 1, (Snow(I).Y + Snow(I).Speed), Snow(I).CLR
  347.                           Else
  348.                             SetPixel Picture1.hdc, (Snow(I).X + Snow(I).Wind), (Snow(I).Y + Snow(I).Speed) - 1, Snow(I).CLR
  349.                         End If
  350.                       Else
  351.                         If BigFlakes Then
  352.                             Picture1.PSet ((Snow(I).X + Snow(I).Wind), ((Snow(I).Y + Snow(I).Speed) - 1)), Snow(I).CLR
  353.                             Picture1.PSet ((Snow(I).X + Snow(I).Wind), ((Snow(I).Y + Snow(I).Speed) - 1) + 1), Snow(I).CLR
  354.                             Picture1.PSet ((Snow(I).X + Snow(I).Wind) + 1, ((Snow(I).Y + Snow(I).Speed) - 1)), Snow(I).CLR
  355.                             Picture1.PSet ((Snow(I).X + Snow(I).Wind) + 1, ((Snow(I).Y + Snow(I).Speed) - 1) + 1), Snow(I).CLR
  356.                           Else
  357.                             Picture1.PSet (Snow(I).X + Snow(I).Wind, (Snow(I).Y + Snow(I).Speed) - 1), Snow(I).CLR
  358.                         End If
  359.                     
  360.                     End If
  361.                     
  362.                 End If
  363.                 If Snow(I).Y > Picture1.ScaleHeight - 10 Then
  364.                     If setPixelIt Then
  365.                         If BigFlakes Then
  366.                             SetPixel Picture1.hdc, (Snow(I).X), (Snow(I).Y), Snow(I).CLR
  367.                             SetPixel Picture1.hdc, (Snow(I).X), (Snow(I).Y) + 1, Snow(I).CLR
  368.                             SetPixel Picture1.hdc, (Snow(I).X) + 1, (Snow(I).Y), Snow(I).CLR
  369.                             SetPixel Picture1.hdc, (Snow(I).X) + 1, (Snow(I).Y) + 1, Snow(I).CLR
  370.                           Else
  371.                             SetPixel Picture1.hdc, (Snow(I).X), (Snow(I).Y), Snow(I).CLR
  372.                         End If
  373.                       Else
  374.                         If BigFlakes Then
  375.                             Picture1.PSet (Snow(I).X, Snow(I).Y), Snow(I).CLR
  376.                             Picture1.PSet (Snow(I).X, Snow(I).Y + 1), Snow(I).CLR
  377.                             Picture1.PSet (Snow(I).X + 1, Snow(I).Y), Snow(I).CLR
  378.                             Picture1.PSet (Snow(I).X + 1, Snow(I).Y + 1), Snow(I).CLR
  379.                           Else
  380.                             Picture1.PSet (Snow(I).X, Snow(I).Y), Snow(I).CLR
  381.                         End If
  382.                     End If
  383.                     Snow(I).X = Int(Rnd * Picture1.ScaleWidth) - 35
  384.                     Snow(I).Y = 0
  385.                 End If
  386.             End If
  387.             'Check if Ended.
  388.             If Ended = True Then GoTo E
  389.         Next I
  390.     'Process the flakes
  391.     For j = 1 To Max_Flakes
  392.         If Ended = True Then GoTo E
  393.         SnowFlakes(j).Y = SnowFlakes(j).Y + SnowFlakes(j).Speed
  394.         If SnowWrap Then
  395.             If SnowFlakes(j).X > Picture1.ScaleWidth Then SnowFlakes(j).X = 0
  396.             If SnowFlakes(j).Y > Picture1.ScaleHeight Then SnowFlakes(j).Y = 0
  397.         End If
  398.         SnowFlakes(j).X = SnowFlakes(j).X + SnowFlakes(j).Wind
  399.         
  400.         'Erase the old Flakes
  401.         If SnowFlakes(j).LastX <> 99999 Then
  402.             'Do nothing
  403.           Else
  404.             'Erase the old one
  405.         End If
  406.         
  407.         'Draw Each Flake
  408.         If SnowFlakes(j).LargeFlake Then
  409.             'First SRCAND the mask down
  410.             BitBlt Picture1.hdc, SnowFlakes(j).X, SnowFlakes(j).Y, 29, 29, picSnowLarge(99).hdc, 29, 0, SRCAND
  411.             'Then SRCCOPY the sprite
  412.             BitBlt Picture1.hdc, SnowFlakes(j).X, SnowFlakes(j).Y, 29, 29, picSnowLarge(99).hdc, 0, 0, SRCPAINT
  413.           Else
  414.             'First SRCAND the mask down
  415.             BitBlt Picture1.hdc, SnowFlakes(j).X, SnowFlakes(j).Y, 15, 15, picSnowSmall.hdc, 15, 0, SRCAND
  416.             'Then SRCCOPY the sprite
  417.             BitBlt Picture1.hdc, SnowFlakes(j).X, SnowFlakes(j).Y, 15, 15, picSnowSmall.hdc, 0, 0, SRCPAINT
  418.         End If
  419.     Next j
  420.     Picture1.Refresh
  421.     FPS = 1000 / (tmr1.Elapsed + 1)
  422.     If BigFlakes Then
  423.         NumSets = Max_Snow * 4
  424.       Else
  425.         NumSets = Max_Snow
  426.     End If
  427.     NumBlts = (Max_Flakes) * 2 + 1
  428.     'Make sure we don't overflow the NumFrame var
  429.     'At 30FPS that would take a little over
  430.     '2 years. Heck, it doesn't hurt to code in for
  431.     'Every possibility...
  432.     If NumFrames > 2000000000 Then
  433.         NumFrames = 0
  434.         TempDBL = 0
  435.     End If
  436.     TempDBL = TempDBL + FPS
  437.     NumFrames = NumFrames + 1
  438.     AvgFPS = TempDBL / NumFrames
  439.     If Not FullScreenSize Then
  440.         Form1.Caption = "3D Snow - (" + Format(Int(FPS)) + ") FPS, " + Format(Int(AvgFPS)) + ") Average FPS, "
  441.       Else
  442.         Picture1.CurrentX = 615
  443.         Picture1.CurrentY = 465
  444.         Picture1.ForeColor = vbWhite
  445.         Picture1.Print Format(Int(FPS))
  446.     End If
  447.     tmr1.StopTimer
  448.     Exit Sub
  449. Unload Me
  450.     End Sub
  451. Sub InitSnow() 'Create Random Locations, Speed and Wind.
  452.     For I = 1 To Max_Snow
  453.         DoEvents
  454.             Snow(I).X = Int(Rnd * Picture1.ScaleWidth)
  455.             Snow(I).Z = Int(Rnd(1) * 5) + 1
  456.             Snow(I).Y = Int(Rnd * Picture1.ScaleHeight)
  457.             If RandSpeed Then
  458.                 Snow(I).Wind = Int(Rnd(1) * 3) + 1
  459.                 Snow(I).Speed = Int(Rnd(1) * 5) + 1
  460.                 Snow(I).CLR = GetSColor(Int(Rnd(1) * 5) + 1)
  461.             Else
  462.                 Select Case Snow(I).Z
  463.                     Case 1
  464.                         Snow(I).Wind = 2
  465.                         Snow(I).Speed = 2
  466.                         Snow(I).CLR = GetSColor(1)
  467.                     Case 2
  468.                         Snow(I).Wind = 2
  469.                         Snow(I).Speed = 3
  470.                         Snow(I).CLR = GetSColor(2)
  471.                     Case 3
  472.                         Snow(I).Wind = 1
  473.                         Snow(I).Speed = 2
  474.                         Snow(I).CLR = GetSColor(3)
  475.                     Case 4
  476.                         Snow(I).Wind = 1
  477.                         Snow(I).Speed = 2
  478.                         Snow(I).CLR = GetSColor(4)
  479.                     Case 5
  480.                         Snow(I).Wind = 1
  481.                         Snow(I).Speed = 1
  482.                         Snow(I).CLR = GetSColor(5)
  483.                 End Select
  484.             End If
  485.         Next
  486.     For I = 1 To Max_Flakes
  487.         SnowFlakes(I).X = Int(Rnd * Picture1.ScaleWidth) - 50
  488.         SnowFlakes(I).Y = Int(Rnd * Picture1.ScaleHeight)
  489.         If Int(Rnd(1) * 2) + 1 = 1 Then
  490.             SnowFlakes(I).LargeFlake = True
  491.           Else
  492.             SnowFlakes(I).LargeFlake = False
  493.         End If
  494.         If RandSpeed Then
  495.             If SnowFlakes(I).LargeFlake Then
  496.                 SnowFlakes(I).Speed = Int(Rnd(1) * 7) + 1
  497.                 SnowFlakes(I).Wind = SnowFlakes(I).Speed - 1
  498.               Else
  499.                 SnowFlakes(I).Speed = Int(Rnd(1) * 4) + 1
  500.                 SnowFlakes(I).Wind = SnowFlakes(I).Speed - 1
  501.             End If
  502.           Else
  503.             If SnowFlakes(I).LargeFlake Then
  504.                 SnowFlakes(I).Speed = 3
  505.                 SnowFlakes(I).Wind = 2
  506.               Else
  507.                 SnowFlakes(I).Speed = 2
  508.                 SnowFlakes(I).Wind = 1
  509.             End If
  510.         End If
  511.         SnowFlakes(I).LastX = 99999
  512.         SnowFlakes(I).lastY = 99999
  513.         If SnowFlakes(I).LargeFlake Then
  514.             SnowFlakes(I).FlakeNum = Int(Rnd(1) * 4)   '0 to 3
  515.         End If
  516.     Next I
  517.     BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hdc, 0, 0, SRCCOPY
  518.     End Sub
  519. Sub cmdApply_Click()
  520.     NumFrames = 0
  521.     TempDBL = 0
  522.     picSnowLarge(99).Picture = picSnowLarge(0).Picture
  523.     picSnowLarge(99).Refresh
  524.     If chkDots.Value = 1 Then BigFlakes = True Else BigFlakes = False
  525.     If chkRandSpeed.Value = 1 Then RandSpeed = True Else RandSpeed = False
  526.     If chkWrap.Value = 1 Then SnowWrap = True Else SnowWrap = False
  527.     If chkRotate.Value = 1 Then RotatingFlakes = True Else RotatingFlakes = False
  528.     'If chkSet.Value = 1 Then setPixelIt = True Else setPixelIt = False
  529.     setPixelIt = True
  530.     If Val(txtDots.Text) > 9999 Or Val(txtDots.Text) < 0 Then txtDots.Text = "500"
  531.     If Val(txtFlakes.Text) > 9999 Or Val(txtFlakes.Text) < 0 Then txtFlakes.Text = "50"
  532.     If Val(txtAngle.Text) > 360 Or Val(txtAngle.Text) < -360 Then txtAngle.Text = "3"
  533.     FLAKEROTATEANGLE = Val(txtAngle.Text)
  534.     Max_Snow = Val(txtDots.Text)
  535.     Max_Flakes = Val(txtFlakes.Text)
  536.     If Not ConfigMode Then
  537.         Call cmdFullScreen_Click
  538.     End If
  539.     InitSnow
  540.     Looper
  541. End Sub
  542. Sub cmdFullScreen_Click()
  543.     'If it's fullscreen, make it normal size, and vise - versa.
  544.     If FullScreenSize Then
  545.         Call DisableCtrlAltDelete(False)
  546.         FullScreenSize = False
  547.         Call SetScreen(False)
  548.         Form1.Caption = "3D Snow"
  549.         Form1.Height = NORMSCREENHEIGHT
  550.         cmdFullScreen.Caption = "&Full Screen"
  551.         Form1.Top = 0
  552.         Form1.Left = 0
  553.         Form1.SetFocus
  554.       Else
  555.         Call DisableCtrlAltDelete(True)
  556.         FullScreenSize = True
  557.         Call SetScreen(True)
  558.         Form1.Caption = ""
  559.         Form1.Height = FULLSCREENHEIGHT
  560.         cmdFullScreen.Caption = "&Original Size"
  561.         Form1.Top = 0
  562.         Form1.Left = 0
  563.         Form1.SetFocus
  564.     End If
  565. End Sub
  566. Private Sub cmdQuit_Click()
  567.     'Self explanatory...
  568.     Ended = True
  569.     DoEvents
  570.     Call DisableCtrlAltDelete(False)
  571.     Unload Me
  572.     End
  573. End Sub
  574. Private Sub cmdQuit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  575.     'This is just to make VB think a little, to help solve a bug of it's - not mine
  576.     'Where you can't click close right after you switch back from full screen
  577.     'Sort of odd, but it's not my fault. This seems to work however.
  578.     DoEvents
  579. End Sub
  580. Private Sub Form_Load()
  581.     'Load the available background options
  582.     GetBackgrounds
  583.     'Find out what the user is running their monitor at right now
  584.     GetScreenInfo
  585.     'Initialize random numbers.
  586.     Randomize Timer
  587.     'Show the main form.
  588.     Me.Show
  589.     'Apply the settings (Sorta cheating, but it makes it work better with less code this way).
  590.     Call cmdApply_Click
  591.     'Make sure the 2 pictures match (Or else it would not look very good)
  592.     Picture2.Width = Picture1.Width
  593.     Picture2.Height = Picture1.Height
  594.     End Sub
  595. Sub Looper()
  596.     'Main loop for the program.
  597.     'Loops until the cows come home, or ENDED=TRUE, Whichever happens first.
  598.     DoEvents
  599.     Do
  600.         DoEvents
  601.         DoSnow
  602.     Loop While Not Ended
  603. End Sub
  604. Function GetSColor(Z As Integer)
  605.     'For the large flakes, this makes their color emulate
  606.     'a 3D look.
  607.     'The Z axis is emulated by color.
  608.     '(distant snow is darker)
  609.     If BigFlakes Then
  610.         Select Case Z
  611.             Case 1
  612.             GetSColor = vbWhite
  613.             Case 2
  614.             GetSColor = vbWhite
  615.             Case 3
  616.             GetSColor = &HE0E0E0
  617.             Case 4
  618.             GetSColor = &HC0C0C0
  619.             Case 5
  620.             GetSColor = &HC0C0C0
  621.             Case Else
  622.             GetSColor = vbWhite
  623.         End Select
  624.     Else
  625.         GetSColor = vbWhite
  626.     End If
  627. End Function
  628. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  629.     If SSMode Then End
  630. End Sub
  631. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  632.     'Tell Windows that it's not in a screensaver mode
  633.     Call DisableCtrlAltDelete(False)
  634.     DoEvents
  635.     'Makes sure we don't stick the user in 640x480.
  636.     If FullScreenSize Then
  637.         Call SetScreen(False)
  638.     End If
  639.     Ended = True
  640.     DoEvents
  641.     Unload Me
  642.     End
  643. End Sub
  644. Private Sub HScroll1_Change()
  645.     Picture2.Picture = LoadPicture(App.Path & "\" + Backgrounds(HScroll1.Value))
  646. End Sub
  647. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  648.     'Just makes the program a little user-friendlier.
  649.     If X > Picture1.ScaleWidth Then Exit Sub
  650.     If Y > Picture1.ScaleHeight Then Exit Sub
  651.     'I really shouldn't have to check those, but ATI's video drivers are BUGGY!!!
  652.     'Why should a picturebox_Mousedown event be called after a screen resolution change
  653.     'Even when the user didn't click on the picturebox, but ANYWHERE ELSE??????????????
  654.     'Then again, it only happens on one of my systems, and nowhere else. Damn ATI Video cards...
  655.     DoEvents
  656.     Call cmdFullScreen_Click
  657. End Sub
  658. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  659.     Static mouse As Integer
  660.     If Not SSMode Then Exit Sub
  661.     mouse = mouse + 1
  662.     If mouse > 8 Then Call cmdQuit_Click
  663. End Sub
  664. Private Sub tmrFlakeHorzRotate_Timer()
  665.     Static ANG As Integer
  666.     If Max_Flakes < 1 Then Exit Sub
  667.     If Not RotatingFlakes Then Exit Sub
  668.     ANG = ANG + FLAKEROTATEANGLE
  669.     If ANG >= 360 Then ANG = 0
  670.     Call RotateFlakes(ANG)
  671.     'Basically, this just rotates the large snowflake 3 degrees counter-clockwise
  672.     'For every call of the timer.
  673. End Sub
  674. Sub SetScreen(Full As Boolean)
  675.     'Thanks go to www.vb-world.net for this tip also.
  676.     'Sets the screen to 640x480 if full=TRUE, otherwise back to the original res if FALSE.
  677.     Dim DevM As DEVMODE
  678.     Dim erg As Long
  679.     Dim an As Variant
  680.     erg& = EnumDisplaySettings(0&, 0&, DevM)
  681.     If Full Then
  682.         ShowCursor (False)
  683.         DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL
  684.         DevM.dmPelsWidth = 640 'ScreenWidth
  685.         DevM.dmPelsHeight = 480 'ScreenHeight
  686.         
  687.         erg& = ChangeDisplaySettings(DevM, CDS_TEST)
  688.         
  689.         Select Case erg&
  690.         Case DISP_CHANGE_SUCCESSFUL
  691.             erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
  692.         Case Else
  693.             MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
  694.         End Select
  695.       Else
  696.         ShowCursor (True)
  697.         DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL
  698.         DevM.dmPelsWidth = OrgScreenX 'ScreenWidth
  699.         DevM.dmPelsHeight = OrgScreenY 'ScreenHeight
  700.         erg& = ChangeDisplaySettings(DevM, CDS_TEST)
  701.         Select Case erg&
  702.         Case DISP_CHANGE_SUCCESSFUL
  703.             erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
  704.         Case Else
  705.             MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
  706.         End Select
  707.     End If
  708. End Sub
  709. Sub GetScreenInfo()
  710.     'Remembers what the res was when the program started, as not to PO the user...
  711.     OrgScreenX = GetSystemMetrics(SM_CXSCREEN)
  712.     OrgScreenY = GetSystemMetrics(SM_CYSCREEN)
  713. End Sub
  714. Public Sub RotatePicture(ByVal SourcehDC As Long, ByVal DesthDC As Long, ByVal AngleInRadians As Double, ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer, ByVal OrigX As Integer, ByVal OrigY As Integer, ByVal NewX As Integer, ByVal NewY As Integer)
  715.     'Thanks go to www.vb-world.net for this tip.
  716.     Dim sin_theta As Double
  717.     Dim cos_theta As Double
  718.     Dim MinX As Integer
  719.     Dim MaxX As Integer
  720.     Dim MinY As Integer
  721.     Dim MaxY As Integer
  722.     Dim tx As Integer
  723.     Dim ty As Integer
  724.     Dim fx As Double
  725.     Dim fy As Double
  726.     Dim ifx As Integer
  727.     Dim ify As Integer
  728.     ' Compute the sine and cosine of theta.
  729.     sin_theta = Sin(AngleInRadians)
  730.     cos_theta = Cos(AngleInRadians)
  731.     ' Make some bounds for new picture
  732.     MinX = (Left - OrigX) * cos_theta + (Top - OrigY) * sin_theta + NewX
  733.     MinY = -(Left - OrigX) * sin_theta + (Top - OrigY) * cos_theta + NewY
  734.     MaxX = MinX
  735.     MaxY = MinY
  736.     tx = (Left - OrigX) * cos_theta + (Bottom - OrigY) * sin_theta + NewX
  737.     ty = -(Left - OrigX) * sin_theta + (Bottom - OrigY) * cos_theta + NewY
  738.     If MinX > tx Then MinX = tx
  739.     If MinY > ty Then MinY = ty
  740.     If MaxX < tx Then MaxX = tx
  741.     If MaxY < ty Then MaxY = ty
  742.     tx = (Right - OrigX) * cos_theta + (Top - OrigY) * sin_theta + NewX
  743.     ty = -(Right - OrigX) * sin_theta + (Top - OrigY) * cos_theta + NewY
  744.     If MinX > tx Then MinX = tx
  745.     If MinY > ty Then MinY = ty
  746.     If MaxX < tx Then MaxX = tx
  747.     If MaxY < ty Then MaxY = ty
  748.     tx = (Right - OrigX) * cos_theta + (Bottom - OrigY) * sin_theta + NewX
  749.     ty = -(Right - OrigX) * sin_theta + (Bottom - OrigY) * cos_theta + NewY
  750.     If MinX > tx Then MinX = tx
  751.     If MinY > ty Then MinY = ty
  752.     If MaxX < tx Then MaxX = tx
  753.     If MaxY < ty Then MaxY = ty
  754.     If MinX < 1 Then MinX = 1
  755.     If MaxX < 1 Then MaxX = 1
  756.     If MinY < 1 Then MinY = 1
  757.     If MaxY < 1 Then MaxY = 1
  758.     ' Perform the rotation.
  759.     For ty = MinY To MaxY
  760.     For tx = MinX To MaxX
  761.     ' Find the location (fx, fy) that maps to the pixel (tx, ty).
  762.     fx = (tx - NewX) * cos_theta - (ty - NewY) * sin_theta + OrigX
  763.     fy = (tx - NewX) * sin_theta + (ty - NewY) * cos_theta + OrigY
  764.     ify = Fix(fy)
  765.     ifx = Fix(fx)
  766.     If ifx >= Left And ifx < Right And ify >= Top And ify < Bottom Then
  767.     Call SetPixelV(DesthDC, tx, ty, GetPixel(SourcehDC, ifx, ify))
  768.     End If
  769.     Next tx
  770.     Next ty
  771. End Sub
  772. Sub RotateFlakes(Angle As Integer)
  773.     'Just calles the picture rotation procedure
  774.     Dim theta As Double
  775.     Dim CurrFlake As Integer
  776.     Dim FlakeRotNum As Byte
  777.     Dim FromHDC As Long
  778.     Dim ToHDC As Long
  779.     Dim FromNum  As Integer
  780.     Dim ToNum As Integer
  781.     lblAngle.Caption = Angle
  782.     FromNum = 0
  783.     ToNum = 99
  784.     theta = Pi * (Angle) / 180
  785.     picSnowLarge(ToNum).Cls
  786.     RotatePicture picSnowLarge(FromNum).hdc, picSnowLarge(ToNum).hdc, _
  787.     theta, 0, 0, ((picSnowLarge(FromNum).ScaleWidth) / 2) - 1, _
  788.     picSnowLarge(FromNum).ScaleHeight - 1, ((picSnowLarge(FromNum).ScaleWidth) / 2) / 2, _
  789.     picSnowLarge(FromNum).ScaleHeight / 2, ((picSnowLarge(ToNum).ScaleWidth) / 2) / 2, _
  790.     picSnowLarge(ToNum).ScaleHeight / 2
  791.     MakeMask (ToNum)
  792.     picSnowLarge(ToNum).Refresh
  793. End Sub
  794. Sub MakeMask(I As Integer)
  795.     'This is my own on the fly mask generator, since none I found could do what I wanted.
  796.     'This procedure is from my castle game - www.comp-info.net/castle
  797.     'Slightly modified to make it work with this program.
  798.     Dim X As Long
  799.     Dim Y As Long
  800.     Dim MaskColor As Long
  801.     MaskColor = vbBlack
  802.     For X = 0 To picSnowLarge(I).ScaleWidth - 1 Step 1
  803.         For Y = 0 To picSnowLarge(I).ScaleHeight - 1 Step 1
  804.             If GetPixel(picSnowLarge(I).hdc, X, Y) = MaskColor Then
  805.                 SetPixel picSnowLarge(I).hdc, X + Int(picSnowLarge(I).ScaleWidth / 2), Y, vbWhite
  806.               Else
  807.                 SetPixel picSnowLarge(I).hdc, X + Int(picSnowLarge(I).ScaleWidth / 2), Y, vbBlack
  808.             End If
  809.         Next
  810.     Next
  811.     picSnowLarge(I).Refresh
  812. End Sub
  813. Sub GetBackgrounds()
  814.     Dim FF As Byte
  815.     Dim I As Integer
  816.     Dim NumBackgrounds As Integer
  817.     FF = FreeFile
  818.     Close   'just to be sure
  819.     Open App.Path & "\backgrnd.dat" For Input As #FF
  820.         Input #FF, NumBackgrounds
  821.         For I = 1 To NumBackgrounds
  822.             Input #FF, Backgrounds(I)
  823.         Next I
  824.     Close #FF
  825.     Close   'Never hurts
  826.     HScroll1.Max = NumBackgrounds
  827. End Sub
  828. Sub DisableCtrlAltDelete(bDisabled As Boolean)
  829.     'Thanks go to www.vb-world.net for this one also.
  830.     Dim X As Long
  831.     X = SystemParametersInfo(97, bDisabled, CStr(1), 0)
  832. End Sub
  833.