home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Particle_E2115926102008.psc / ParticlesPSC / Main.frm < prev    next >
Text File  |  2008-06-10  |  29KB  |  981 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00E0E0E0&
  5.    BorderStyle     =   3  'Fixed Dialog
  6.    Caption         =   " Particle Effects Demo"
  7.    ClientHeight    =   9855
  8.    ClientLeft      =   150
  9.    ClientTop       =   450
  10.    ClientWidth     =   11445
  11.    ForeColor       =   &H00000000&
  12.    Icon            =   "Main.frx":0000
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   657
  17.    ScaleMode       =   3  'Pixel
  18.    ScaleWidth      =   763
  19.    ShowInTaskbar   =   0   'False
  20.    StartUpPosition =   2  'CenterScreen
  21.    Begin VB.PictureBox picCTRL 
  22.       Appearance      =   0  'Flat
  23.       AutoRedraw      =   -1  'True
  24.       BackColor       =   &H0080C0FF&
  25.       ForeColor       =   &H80000008&
  26.       Height          =   780
  27.       Left            =   0
  28.       ScaleHeight     =   50
  29.       ScaleMode       =   3  'Pixel
  30.       ScaleWidth      =   750
  31.       TabIndex        =   2
  32.       Top             =   6780
  33.       Width           =   11280
  34.       Begin VB.CommandButton cmdSound 
  35.          BackColor       =   &H0080C0FF&
  36.          Caption         =   "Sound ON"
  37.          Height          =   510
  38.          Left            =   1020
  39.          Style           =   1  'Graphical
  40.          TabIndex        =   19
  41.          Top             =   105
  42.          Width           =   945
  43.       End
  44.       Begin VB.OptionButton optType 
  45.          BackColor       =   &H0080C0FF&
  46.          Caption         =   "Wiper"
  47.          Height          =   225
  48.          Index           =   7
  49.          Left            =   9585
  50.          TabIndex        =   18
  51.          Top             =   90
  52.          Width           =   900
  53.       End
  54.       Begin VB.OptionButton optType 
  55.          BackColor       =   &H0080C0FF&
  56.          Caption         =   "Expand"
  57.          Height          =   225
  58.          Index           =   6
  59.          Left            =   8610
  60.          TabIndex        =   17
  61.          Top             =   90
  62.          Width           =   900
  63.       End
  64.       Begin VB.OptionButton optType 
  65.          BackColor       =   &H0080C0FF&
  66.          Caption         =   "Spirals"
  67.          Height          =   225
  68.          Index           =   5
  69.          Left            =   7725
  70.          TabIndex        =   16
  71.          Top             =   90
  72.          Width           =   900
  73.       End
  74.       Begin VB.OptionButton optType 
  75.          BackColor       =   &H0080C0FF&
  76.          Caption         =   "Wavy"
  77.          Height          =   225
  78.          Index           =   4
  79.          Left            =   6615
  80.          TabIndex        =   15
  81.          Top             =   90
  82.          Width           =   900
  83.       End
  84.       Begin VB.OptionButton optType 
  85.          BackColor       =   &H0080C0FF&
  86.          Caption         =   "Spray"
  87.          Height          =   225
  88.          Index           =   3
  89.          Left            =   9585
  90.          TabIndex        =   14
  91.          Top             =   360
  92.          Width           =   900
  93.       End
  94.       Begin VB.OptionButton optType 
  95.          BackColor       =   &H0080C0FF&
  96.          Caption         =   "Spurt"
  97.          Height          =   225
  98.          Index           =   2
  99.          Left            =   8610
  100.          TabIndex        =   13
  101.          Top             =   360
  102.          Width           =   900
  103.       End
  104.       Begin VB.OptionButton optType 
  105.          BackColor       =   &H0080C0FF&
  106.          Caption         =   "Hot"
  107.          Height          =   225
  108.          Index           =   1
  109.          Left            =   7740
  110.          TabIndex        =   12
  111.          Top             =   360
  112.          Width           =   615
  113.       End
  114.       Begin VB.OptionButton optType 
  115.          BackColor       =   &H0080C0FF&
  116.          Caption         =   "Fountain"
  117.          Height          =   225
  118.          Index           =   0
  119.          Left            =   6615
  120.          TabIndex        =   11
  121.          Top             =   360
  122.          Value           =   -1  'True
  123.          Width           =   1050
  124.       End
  125.       Begin VB.HScrollBar scrSpeed 
  126.          Height          =   195
  127.          Left            =   4440
  128.          Max             =   90
  129.          Min             =   10
  130.          TabIndex        =   7
  131.          TabStop         =   0   'False
  132.          Top             =   390
  133.          Value           =   10
  134.          Width           =   1800
  135.       End
  136.       Begin VB.HScrollBar scrAngle 
  137.          Height          =   195
  138.          Left            =   2520
  139.          Max             =   110
  140.          Min             =   70
  141.          TabIndex        =   5
  142.          TabStop         =   0   'False
  143.          Top             =   390
  144.          Value           =   70
  145.          Width           =   1800
  146.       End
  147.       Begin VB.CommandButton cmdStart 
  148.          BackColor       =   &H0080C0FF&
  149.          Caption         =   "Start"
  150.          BeginProperty Font 
  151.             Name            =   "MS Sans Serif"
  152.             Size            =   8.25
  153.             Charset         =   0
  154.             Weight          =   700
  155.             Underline       =   0   'False
  156.             Italic          =   0   'False
  157.             Strikethrough   =   0   'False
  158.          EndProperty
  159.          Height          =   510
  160.          Left            =   60
  161.          Style           =   1  'Graphical
  162.          TabIndex        =   3
  163.          Top             =   105
  164.          Width           =   720
  165.       End
  166.       Begin VB.Label Label2 
  167.          BackColor       =   &H0080C0FF&
  168.          Caption         =   "Speed"
  169.          Height          =   195
  170.          Index           =   1
  171.          Left            =   4680
  172.          TabIndex        =   10
  173.          Top             =   150
  174.          Width           =   645
  175.       End
  176.       Begin VB.Label Label2 
  177.          BackColor       =   &H0080C0FF&
  178.          Caption         =   "Angle"
  179.          Height          =   195
  180.          Index           =   0
  181.          Left            =   2790
  182.          TabIndex        =   9
  183.          Top             =   150
  184.          Width           =   510
  185.       End
  186.       Begin VB.Label LabSpeed 
  187.          Alignment       =   2  'Center
  188.          Appearance      =   0  'Flat
  189.          BackColor       =   &H80000005&
  190.          BorderStyle     =   1  'Fixed Single
  191.          ForeColor       =   &H80000008&
  192.          Height          =   255
  193.          Left            =   5460
  194.          TabIndex        =   8
  195.          Top             =   90
  196.          Width           =   555
  197.       End
  198.       Begin VB.Label LabAngle 
  199.          Alignment       =   2  'Center
  200.          Appearance      =   0  'Flat
  201.          BackColor       =   &H80000005&
  202.          BorderStyle     =   1  'Fixed Single
  203.          ForeColor       =   &H80000008&
  204.          Height          =   255
  205.          Left            =   3615
  206.          TabIndex        =   6
  207.          Top             =   90
  208.          Width           =   555
  209.       End
  210.       Begin VB.Label Label1 
  211.          Alignment       =   2  'Center
  212.          Appearance      =   0  'Flat
  213.          BackColor       =   &H00FFFFFF&
  214.          BorderStyle     =   1  'Fixed Single
  215.          ForeColor       =   &H00000000&
  216.          Height          =   255
  217.          Left            =   10485
  218.          TabIndex        =   4
  219.          Top             =   390
  220.          Width           =   765
  221.       End
  222.    End
  223.    Begin VB.PictureBox picIN 
  224.       Appearance      =   0  'Flat
  225.       AutoRedraw      =   -1  'True
  226.       AutoSize        =   -1  'True
  227.       BackColor       =   &H80000005&
  228.       BorderStyle     =   0  'None
  229.       ForeColor       =   &H80000008&
  230.       Height          =   1395
  231.       Left            =   11760
  232.       ScaleHeight     =   93
  233.       ScaleMode       =   3  'Pixel
  234.       ScaleWidth      =   97
  235.       TabIndex        =   1
  236.       Top             =   900
  237.       Visible         =   0   'False
  238.       Width           =   1455
  239.    End
  240.    Begin VB.PictureBox PIC 
  241.       Appearance      =   0  'Flat
  242.       AutoRedraw      =   -1  'True
  243.       AutoSize        =   -1  'True
  244.       BackColor       =   &H00C0C0C0&
  245.       ForeColor       =   &H80000008&
  246.       Height          =   6750
  247.       Left            =   0
  248.       ScaleHeight     =   448
  249.       ScaleMode       =   3  'Pixel
  250.       ScaleWidth      =   750
  251.       TabIndex        =   0
  252.       Top             =   0
  253.       Width           =   11280
  254.       Begin VB.Image imEmit 
  255.          Height          =   330
  256.          Left            =   5415
  257.          Picture         =   "Main.frx":18BA
  258.          Top             =   6360
  259.          Width           =   420
  260.       End
  261.    End
  262.    Begin VB.Menu mnuOpen 
  263.       Caption         =   "&Open"
  264.    End
  265.    Begin VB.Menu mnuSave 
  266.       Caption         =   "&Save As"
  267.    End
  268.    Begin VB.Menu mnuExit 
  269.       Caption         =   "E&xit"
  270.    End
  271. End
  272. Attribute VB_Name = "Form1"
  273. Attribute VB_GlobalNameSpace = False
  274. Attribute VB_Creatable = False
  275. Attribute VB_PredeclaredId = True
  276. Attribute VB_Exposed = False
  277. ' Particle Effects Demo  by  Robert Rayment
  278. ' June 2008
  279.  
  280. ' Update 10 June 08
  281.  
  282. '1. Minor update Sound ON/OFF caption changed.
  283.  
  284. Option Explicit
  285.  
  286. ' Loaded image size
  287. Private picwidth As Long
  288. Private picheight  As Long
  289. ' Display image size
  290. Private W As Long, H As Long  ' Image width & hweight
  291.  
  292. Private FPS As Long  ' Frames Per Second
  293. Private aDone As Boolean   ' Loop exit
  294.  
  295. ' Particles
  296. Private xp() As Long, yp() As Long  ' Pixel centre coords
  297. Private NumParticles As Long        ' Number of particles
  298. Private Breadth As Long             ' Random Breadth of particles
  299. ' Colors
  300. Private CCen As Long
  301. Private CTop As Long, CLef As Long, CRit As Long, CBot As Long
  302.  
  303. Private CenR As Byte, CenG As Byte, CenB As Byte
  304. Private TopR As Byte, TopG As Byte, TopB As Byte
  305. Private LefR As Byte, LefG As Byte, LefB As Byte
  306. Private RitR As Byte, RitG As Byte, RitB As Byte
  307. Private BotR As Byte, BotG As Byte, BotB As Byte
  308.  
  309. Private Red As Byte, Green As Byte, Blue As Byte
  310.  
  311. ' Emitter
  312. Private imx As Single, imy As Single
  313. Private imMouseDown As Boolean
  314. Private OldX As Long
  315. Private OldY As Long
  316. Private EmitType As Long
  317.  
  318. ' Parabolic parameters & scrollbars
  319. Private MaxSpeed As Single
  320. Private Grav As Single
  321. Private Angle As Single
  322. Private sAngle As Single
  323. Private aScroll As Boolean
  324.  
  325. ' Timing
  326. Private TT As Long
  327. Private TimeElapsed As Single         ' ms
  328. Private TimeLng As Long               ' Int ms
  329. Private ScaledTime As Single
  330. Private MaxScaledTime As Single
  331. Private ST As Single
  332. Private STDiv As Long
  333.  
  334. ' File
  335. Private PathSpec$, CurrentPath$, FileSpec$
  336. Private SavePath$, SaveSpec$
  337.  
  338. Dim CommonDialog1 As cOSDialog
  339.  
  340. Dim tmr As CTiming   ' For cTimLNG.cls
  341.  
  342. ' picDATAORG(x,y)
  343. ' picDATA(x,y)
  344. ' For picDATA(x,y) color: use RGB(Blue,Green,Red) ie Red & Blue swapped
  345. ' y = H-1
  346. '  ^
  347. '  |
  348. ' y = 0
  349.  
  350. Private Sub cmdStart_Click()
  351. Dim k As Long
  352. Dim Speed As Single  ' Varing speed (Pressure, Spread)
  353. Dim B As Single      ' Varying breadth as (yp())
  354. Dim S As Single      ' Variable
  355. Dim rad As Single    ' Variable
  356.  
  357. ' imEmit
  358. Dim imx As Single
  359. Dim imxStart As Single
  360.  
  361.    If aDone = False Then
  362.       aDone = True
  363.       If aSound Then StopPlay
  364.       cmdStart.Caption = "Start"
  365.       Exit Sub
  366.    End If
  367.    cmdStart.Caption = "Stop"
  368.    
  369.    aDone = False
  370.    
  371.    FPS = 0
  372.    ' T&E
  373.    Breadth = 25
  374.    Grav = -9.8 / 300
  375.    ScaledTime = 0
  376.    Speed = 0
  377.    
  378.    If EmitType = 4 Then ' ie Wavy start in middle
  379.       imEmit.Left = W / 2
  380.    End If
  381.    
  382.    ' Sound 101,102,,,108
  383.    Play CInt(EmitType)  ' = 0,1,2,3,4,5,6,7
  384.    
  385.    imxStart = imEmit.Left
  386.    Do
  387.       imx = imEmit.Left + imEmit.Width \ 2
  388.       tmr.Reset
  389.       ' Reset to background image
  390.       picDATA() = picDATAORG()
  391.       
  392.       For k = 0 To NumParticles - 1
  393.          Angle = sAngle * d2r# + (Rnd - 0.5) / 10
  394.          ' EmitType = 0 Fountain, 1 Hot, 2 Spurt, 3 Spray
  395.          '            4 Wavy, 5 Spirals, 6 Expand, 7 Wiper
  396.          ' STDiv = 15,45,45,45,45,45,45,45 for EmitType 0,1,2,3,4,5,6,7
  397.          ST = ScaledTime + (k / STDiv)
  398.          
  399.          Select Case EmitType
  400.          Case 0, 1, 2   ' Fountain,Hot,Spurt
  401.             ' Parabolic
  402.             yp(k) = 0.5 * Grav * (ST * ST) + Speed * Sin(Angle) * ST
  403.             xp(k) = MaxSpeed * Cos(Angle) * ST
  404.             xp(k) = xp(k) + imx
  405.             B = yp(k) * Breadth / (H - 1)
  406.          Case 3   ' Spray
  407.             rad = k * NumParticles / H
  408.             yp(k) = rad * Sin(Angle) / (ST + 60)
  409.             If Speed > 1 Then
  410.                B = yp(k) * Breadth / (2 * H - 1)
  411.             Else
  412.                B = yp(k) * 10 / (2 * H - 1)
  413.             End If
  414.                xp(k) = MaxSpeed * rad * Cos(Angle) * Speed / 45
  415.                xp(k) = xp(k) + imx
  416.          Case 4   ' Wavy
  417.             rad = k * NumParticles / H
  418.             yp(k) = MaxSpeed / 2 * rad * Sin(Angle) / (ST + 60)
  419.             xp(k) = (yp(k) / 2) * Sin(2 * pi# / (H / 5) * ST)
  420.             ' Oscillate emitter
  421.             S = 4 * pi# / MaxScaledTime * ScaledTime
  422.             imEmit.Left = imxStart * (1 + 0.25 * Sin(S))
  423.             xp(k) = xp(k) + imEmit.Left + imEmit.Width \ 2
  424.             B = 20 * Sin((sAngle - 90) * d2r#)
  425.          Case 5   ' Spirals
  426.             rad = k * Speed * NumParticles / H
  427.             S = 0.25 * ST * k * MaxSpeed
  428.             yp(k) = S * Sin(rad) / NumParticles
  429.             xp(k) = S * Cos(rad) / NumParticles
  430.             xp(k) = xp(k) + imEmit.Left + imEmit.Width \ 2
  431.             B = 20 * Sin((sAngle - 90) * d2r#)
  432.          Case 6   ' Expand
  433.             rad = k * NumParticles / H
  434.             rad = rad * rad * Speed
  435.             S = 0.25 * ST * k * MaxSpeed
  436.             yp(k) = S * Sin(rad) / NumParticles
  437.             xp(k) = S * Cos(rad) / NumParticles
  438.             xp(k) = xp(k) + imEmit.Left + imEmit.Width \ 2
  439.             B = 20 * Sin((sAngle - 90) * d2r#)
  440.          Case 7   ' Wiper
  441.             rad = k * MaxSpeed * NumParticles / H
  442.             yp(k) = k * ST * Tan(rad) / NumParticles
  443.             xp(k) = k * ST * Tan(rad) / NumParticles
  444.             S = sAngle / 10 - 90
  445.             S = S * d2r# * ScaledTime
  446.             xp(k) = xp(k) * Cos(S)
  447.             xp(k) = xp(k) + imEmit.Left + imEmit.Width \ 2
  448.             B = MaxSpeed - 0.45
  449.             xp(k) = xp(k) + (Rnd - 0.5) * B * 10
  450.          End Select
  451.          
  452.          yp(k) = yp(k) + (Rnd - 0.5) * B * 10  ' B*10 gives spread
  453.          yp(k) = yp(k) + (H - imEmit.Top)
  454.       
  455.          ' Test boundaries
  456.          If xp(k) < 0 Then
  457.             xp(k) = 0
  458.          ElseIf xp(k) > W - 2 Then
  459.             xp(k) = W - 2
  460.          End If
  461.          Select Case EmitType
  462.          Case 0, 1, 2   ' Fountain,Hot
  463.             If yp(k) < H - (imEmit.Top + imEmit.Height) + 1 Then
  464.                yp(k) = H - (imEmit.Top + imEmit.Height) + 1
  465.             ElseIf yp(k) > H - 2 Then
  466.                yp(k) = H - 2
  467.             End If
  468.          Case Else
  469.             If yp(k) < 1 Then
  470.                yp(k) = 1
  471.             ElseIf yp(k) > H - 2 Then
  472.                yp(k) = H - 2
  473.             End If
  474.          End Select
  475.          
  476.          ' Color particle k Colors set for each EmitType
  477.          ' 0 1 0
  478.          ' 1 1 1
  479.          ' 0 1 0
  480.          ' Centre
  481.          picDATA(xp(k), yp(k)) = CCen
  482.          If xp(k) > 1 Then
  483.             ' Left
  484.             picDATA(xp(k) - 1, yp(k)) = CLef
  485.             ' Right
  486.             picDATA(xp(k) + 1, yp(k)) = CRit
  487.          End If
  488.          
  489.          If yp(k) > H - (imEmit.Top + imEmit.Height) + 1 Then
  490.             ' Top Displays above yp(k)-1
  491.             picDATA(xp(k), yp(k) + 1) = CTop
  492.             ' Bottom
  493.             picDATA(xp(k), yp(k) - 1) = CBot
  494.          End If
  495.       Next k
  496.       
  497.       ' 0 Fountain, 1 Hot, 2 Spurt, 3 Spray,
  498.       ' 4 Wavy, 5 Spirals, 6 Expand, 7 Wiper
  499.       Select Case EmitType
  500.       Case 0, 2, 5, 6, 7
  501.       '
  502.       Case 1, 3, 4 ' BLEND
  503.          For k = 0 To NumParticles - 1
  504.             If xp(k) > 1 Then
  505.                ' Left
  506.                'picDATA(xp(k) - 1, yp(k)) = CLef
  507.                LngToRGB picDATAORG(xp(k) - 2, yp(k)), Blue, Green, Red
  508.                picDATA(xp(k) - 2, yp(k)) = _
  509.                   RGB((1& * Blue + LefB) \ 2, (1& * Green + LefG) \ 2, (1& * Red + LefR) \ 2)
  510.             End If
  511.          
  512.             If yp(k) < H - 2 Then
  513.                ' Top Displays above yp(k)-1
  514.                'picDATA(xp(k), yp(k) + 1) = CTop
  515.                LngToRGB picDATAORG(xp(k), yp(k) + 2), Blue, Green, Red
  516.                picDATA(xp(k), yp(k) + 2) = _
  517.                   RGB((1& * Blue + TopB) \ 2, (1& * Green + TopG) \ 2, (1& * Red + TopR) \ 2)
  518.             End If
  519.          
  520.             If xp(k) > 1 And yp(k) < H - 2 Then
  521.                ' Top-Left
  522.                picDATA(xp(k) - 1, yp(k) + 1) = picDATAORG(xp(k), yp(k) + 2)
  523.             End If
  524.             
  525.             If xp(k) < W - 2 And yp(k) < H - 2 Then
  526.                ' Top-Right
  527.                picDATA(xp(k) + 1, yp(k) + 1) = picDATAORG(xp(k), yp(k) + 2)
  528.             End If
  529.          Next k
  530.       End Select
  531.       
  532.       DISPLAY PIC, picDATA()  ' NB Inline DISPLAY not worth it!
  533.       
  534.       TT = CLng(tmr.Elapsed)
  535.       ' Delayer
  536.       Do
  537.          TimeElapsed = CLng(tmr.Elapsed)
  538.          TimeLng = CLng(TimeElapsed / 10)
  539.          TimeLng = 10 * TimeLng
  540.          If TimeLng <> 0 And (TimeLng Mod 2) = 0 Then
  541.             Exit Do
  542.          End If
  543.       Loop
  544.       
  545.       ' Increase Speed up to scrSpeed value ie MaxSpeed
  546.       ' Grows from Emitter MaxSpeed = .5 to 4.5
  547.       Speed = Speed + 0.05
  548.       If Speed > MaxSpeed Then Speed = MaxSpeed
  549.  
  550.       FPS = 1000 / TT 'TimeLng
  551.       Label1 = "fps =" & Str$(FPS)
  552.       ScaledTime = ScaledTime + 4.5
  553.       ' MaxScaledTime = 30,16,350,30,350,350,350,350  EmitType 0,1,2,3,4,5,6,7
  554.       If ScaledTime > MaxScaledTime Then ScaledTime = 0
  555.       DoEvents
  556.    Loop Until aDone
  557.    StopPlay
  558. End Sub
  559.  
  560. Private Sub cmdSound_Click()
  561.    aDone = True
  562.    aSound = Not aSound
  563.    If Not aSound Then
  564.       StopPlay
  565.       cmdSound.Caption = "Sound ON"
  566.    Else
  567.       cmdSound.Caption = "Sound OFF"
  568.    End If
  569.    PIC.SetFocus
  570.    cmdStart_Click
  571. End Sub
  572.  
  573. Private Sub Form_Load()
  574. Dim FormW As Long
  575. Dim FormH As Long
  576. Dim BorderW As Long
  577. Dim BorderH As Long
  578. Dim CapH As Long
  579. Dim MenuH As Long
  580.  
  581. 'Dim mHDC  As Long
  582. 'Dim mBMPold As Long
  583.    
  584.    PathSpec$ = App.Path
  585.    If Right$(PathSpec$, 1) <> "\" Then PathSpec$ = PathSpec$ & "\"
  586.    CurrentPath$ = PathSpec$
  587.    
  588.    STX = Screen.TwipsPerPixelX
  589.    STY = Screen.TwipsPerPixelY
  590.    ' Display size
  591.    W = 752
  592.    H = 424 + 20
  593.    
  594.    PIC.Move 0, 2, W, H
  595.    picCTRL.Move 0, PIC.Top + PIC.Height, W, 52
  596.    imEmit.Top = PIC.Top + PIC.Height - imEmit.Height - 1
  597.    
  598.    ' Size Form
  599.    CapH = GetSystemMetrics(SM_CYCAPTION)
  600.    MenuH = GetSystemMetrics(SM_CYMENU)
  601.    BorderW = GetSystemMetrics(SM_CXBORDER)
  602.    BorderH = GetSystemMetrics(SM_CYBORDER)
  603.    FormW = (W + 2 * BorderW + 4) * STX
  604.    FormH = (H + picCTRL.Height) * STY
  605.    FormH = FormH + (CapH + MenuH + 2 * BorderH) * STY
  606.    Form1.Width = FormW
  607.    Form1.Height = FormH
  608.    
  609.    picIN.AutoSize = True
  610.    FileSpec$ = PathSpec$ & "Pics/Ancient.jpg"
  611.    INITPIC
  612.    
  613.    Set tmr = New CTiming
  614.    imEmit.Left = W \ 2
  615.    OldX = imEmit.Left
  616.    
  617.    aScroll = False
  618.    scrAngle.Value = 90  ' Min/Max 70 - 110
  619.    sAngle = 90
  620.    LabAngle = 0
  621.    
  622.    scrSpeed.Value = 90  ' Min/Max 10 - 90
  623.    MaxSpeed = 4.5
  624.    LabSpeed = Str$(4.5)
  625.    optType_Click 0
  626.    aScroll = True
  627.    
  628.    LoadWavs
  629.    aSound = False
  630.    
  631.    Show
  632.  
  633.    NumParticles = 5000  ' 25,000 pixels
  634.    ReDim xp(0 To NumParticles - 1)
  635.    ReDim yp(0 To NumParticles - 1)
  636.    
  637. End Sub
  638.  
  639. Private Sub INITPIC()
  640. ' Private FileSpec$
  641. Dim mHDC  As Long
  642. Dim mBMPold As Long
  643.    picIN.Picture = LoadPicture(FileSpec$)
  644.    GetObject picIN.Image, Len(PicInfo), PicInfo
  645.    picwidth = PicInfo.bmWidth
  646.    picheight = PicInfo.bmHeight
  647.    
  648.    'Stretch whole Image from picIN to PIC
  649.    SetStretchBltMode PIC.hdc, HALFTONE
  650.    StretchBlt PIC.hdc, 0, 0, W, H, _
  651.       picIN.hdc, 0, 0, picwidth, picheight, SRCCOPY
  652.    PIC.Refresh
  653.    With picIN
  654.       .Picture = LoadPicture
  655.       .Width = 4
  656.       .Height = 4
  657.    End With
  658.    ReDim picDATAORG(0 To W - 1, 0 To H - 1)
  659.    ReDim picDATA(0 To W - 1, 0 To H - 1)
  660.    ' Public BHI As BITMAPINFOHEADER
  661.    With BHI
  662.       .biSize = 40
  663.       .biPlanes = 1
  664.       .biWidth = W
  665.       .biHeight = H
  666.       .biBitCount = 32
  667.    End With
  668.    mHDC = CreateCompatibleDC(0)
  669.    mBMPold = SelectObject(mHDC, PIC.Image)
  670.    If GetDIBits(mHDC, PIC.Image, 0, H, picDATAORG(0, 0), BHI, 0) = 0 Then
  671.       MsgBox "DIB ERROR", vbCritical, "Fountain"
  672.       Stop
  673.       Exit Sub
  674.    End If
  675.    SelectObject mHDC, mBMPold
  676.    DeleteDC mHDC
  677.    picDATA() = picDATAORG()
  678.  
  679. End Sub
  680.  
  681. Private Sub mnuOpen_Click()
  682. Dim Title$, Filt$, Indir$
  683. Dim FIndex As Long
  684.    
  685.    aDone = True
  686.    If aSound Then StopPlay
  687.    aSound = False
  688.    cmdSound.Caption = "Sound OFF"
  689.    cmdStart.Caption = "Start"
  690.       
  691.    Title$ = "Open a picture file"
  692.    Filt$ = "Pics bmp,jpg,gif|*.bmp;*.jpg;*.gif"
  693.    FileSpec$ = ""
  694.    Indir$ = CurrentPath$ 'Pathspec$
  695.    Set CommonDialog1 = New cOSDialog
  696.    CommonDialog1.ShowOpen FileSpec$, Title$, Filt$, Indir$, "", Me.hWnd, FIndex
  697.    Set CommonDialog1 = Nothing
  698.    
  699.    If Len(FileSpec$) = 0 Then Exit Sub
  700.    CurrentPath$ = FileSpec$
  701.    
  702.    INITPIC
  703.  
  704. End Sub
  705.  
  706. Private Sub mnuSave_Click()
  707. Dim Title$, Filt$, Indir$
  708. Dim FIndex As Long
  709.    
  710.    aDone = True
  711.    If aSound Then StopPlay
  712.    aSound = False
  713.    cmdSound.Caption = "Sound OFF"
  714.    cmdStart.Caption = "Start"
  715.       
  716.    Title$ = "Save Displayed Image"
  717.    Filt$ = "Pics bmp|*.bmp"
  718.    SaveSpec$ = ""
  719.    Indir$ = SavePath$
  720.    Set CommonDialog1 = New cOSDialog
  721.    CommonDialog1.ShowSave SaveSpec$, Title$, Filt$, Indir$, "", Me.hWnd, FIndex
  722.    Set CommonDialog1 = Nothing
  723.    
  724.    If Len(SaveSpec$) = 0 Then Exit Sub
  725.    FixExtension SaveSpec$, ".bmp"
  726.    SavePath$ = SaveSpec$
  727.    SavePicture PIC.Image, SaveSpec$
  728. End Sub
  729.  
  730. Private Sub FixExtension(FSpec$, Ext$)
  731. ' In: SaveSpec$ & Ext$ (".xxx")
  732. Dim p As Long
  733.    If Len(FSpec$) = 0 Then Exit Sub
  734.    Ext$ = LCase$(Ext$)
  735.    p = InStr(1, FSpec$, ".")
  736.    If p = 0 Then
  737.       FSpec$ = FSpec$ & Ext$
  738.    Else
  739.       FSpec$ = Mid$(FSpec$, 1, p - 1) & Ext$
  740.    End If
  741. End Sub
  742.  
  743.  
  744. ' Color Types
  745. Private Sub optType_Click(Index As Integer)
  746. 'NB RGB (B,G,R)  ie B & R reversed
  747.    aDone = True
  748.    StopPlay
  749.    ' Reset to background image
  750.    picDATA() = picDATAORG()
  751.    DISPLAY PIC, picDATA()  ' NB Inline DISPLAY not worth it!
  752.    EmitType = Index
  753.    Label2(0) = "Angle"
  754.    Label2(1) = "Pressure"
  755.    Select Case Index
  756.    Case 0   ' Fountain
  757.       CCen = RGB(255, 255, 255)
  758.       CTop = RGB(255, 255, 255)
  759.       CLef = RGB(255, 255, 255)
  760.       CRit = RGB(255, 255, 0)
  761.       CBot = RGB(255, 0, 0)    ' ie Blue
  762.       STDiv = 15
  763.       MaxScaledTime = 30
  764.    Case 1   ' Hot
  765.       CenR = 255: CenG = 255: CenB = 0
  766.       CCen = RGB(CenB, CenG, CenR)
  767.       
  768.       TopR = 255: TopG = 0: TopB = 0
  769.       CTop = RGB(TopB, TopG, TopR)
  770.       
  771.       LefR = 255: LefG = 255: LefB = 0
  772.       CLef = RGB(LefB, LefG, LefR)
  773.       
  774.       RitR = 255: RitG = 255: RitB = 0
  775.       CRit = RGB(RitB, RitG, RitB)
  776.       
  777.       BotR = 255: BotG = 255: BotB = 0
  778.       CBot = RGB(BotB, BotG, BotR)
  779.       STDiv = 45
  780.       MaxScaledTime = 16
  781.    Case 2   ' Spurt
  782.       CenR = 255: CenG = 255: CenB = 255
  783.       CCen = RGB(CenB, CenG, CenR)
  784.       
  785.       TopR = 200: TopG = 200: TopB = 200
  786.       CTop = RGB(TopB, TopG, TopR)
  787.       
  788.       LefR = 128: LefG = 128: LefB = 128
  789.       CLef = RGB(LefB, LefG, LefR)
  790.       
  791.       RitR = 0: RitG = 0: RitB = 0
  792.       CRit = RGB(RitB, RitG, RitB)
  793.       
  794.       BotR = 64: BotG = 64: BotB = 64
  795.       CBot = RGB(BotB, BotG, BotR)
  796.       STDiv = 45
  797.       MaxScaledTime = 350
  798.    Case 3   ' Spray
  799.       Label2(1) = "Spread"
  800.       CenR = 128: CenG = 128: CenB = 128
  801.       CCen = RGB(CenB, CenG, CenR)
  802.       
  803.       TopR = 255: TopG = 255: TopB = 255
  804.       CTop = RGB(TopB, TopG, TopR)
  805.       
  806.       LefR = 255: LefG = 255: LefB = 255
  807.       CLef = RGB(LefB, LefG, LefR)
  808.       
  809.       RitR = 0: RitG = 0: RitB = 0
  810.       CRit = RGB(RitB, RitG, RitB)
  811.       
  812.       BotR = 64: BotG = 64: BotB = 64
  813.       CBot = RGB(BotB, BotG, BotR)
  814.       STDiv = 45
  815.       MaxScaledTime = 30
  816.    Case 4   ' Wavy
  817.       Label2(0) = "Spread"
  818.       CenR = 0: CenG = 128: CenB = 255
  819.       CCen = RGB(CenB, CenG, CenR)
  820.       
  821.       TopR = 200: TopG = 200: TopB = 200
  822.       CTop = RGB(TopB, TopG, TopR)
  823.       
  824.       LefR = 128: LefG = 128: LefB = 128
  825.       CLef = RGB(LefB, LefG, LefR)
  826.       
  827.       RitR = 128: RitG = 128: RitB = 128
  828.       CRit = RGB(RitB, RitG, RitB)
  829.       
  830.       BotR = 64: BotG = 64: BotB = 64
  831.       CBot = RGB(BotB, BotG, BotR)
  832.       STDiv = 45
  833.       MaxScaledTime = 350
  834.       imEmit.Left = W / 2
  835.    Case 5   ' Spirals
  836.       Label2(0) = "Spread"
  837.       CenR = 0: CenG = 128: CenB = 255
  838.       CCen = RGB(CenB, CenG, CenR)
  839.       
  840.       TopR = 200: TopG = 200: TopB = 200
  841.       CTop = RGB(TopB, TopG, TopR)
  842.       
  843.       LefR = 128: LefG = 128: LefB = 128
  844.       CLef = RGB(LefB, LefG, LefR)
  845.       
  846.       RitR = 128: RitG = 128: RitB = 128
  847.       CRit = RGB(RitB, RitG, RitB)
  848.       
  849.       BotR = 64: BotG = 64: BotB = 64
  850.       CBot = RGB(BotB, BotG, BotR)
  851.       STDiv = 45
  852.       MaxScaledTime = 350
  853.       imEmit.Left = W / 2
  854.    Case 6   ' Expand
  855.       Label2(0) = "Spread"
  856.       CenR = 255: CenG = 0: CenB = 0
  857.       CCen = RGB(CenB, CenG, CenR)
  858.       
  859.       TopR = 255: TopG = 0: TopB = 0
  860.       CTop = RGB(TopB, TopG, TopR)
  861.       
  862.       LefR = 255: LefG = 255: LefB = 0
  863.       CLef = RGB(LefB, LefG, LefR)
  864.       
  865.       RitR = 128: RitG = 128: RitB = 128
  866.       CRit = RGB(RitB, RitG, RitB)
  867.       
  868.       BotR = 64: BotG = 64: BotB = 64
  869.       CBot = RGB(BotB, BotG, BotR)
  870.       STDiv = 45
  871.       MaxScaledTime = 350
  872.       imEmit.Left = W / 2
  873.    Case 7   ' Wiper
  874.       Label2(0) = "Speed"
  875.       Label2(1) = "Spread"
  876.       CenR = 255: CenG = 0: CenB = 0
  877.       CCen = RGB(CenB, CenG, CenR)
  878.       
  879.       TopR = 255: TopG = 0: TopB = 0
  880.       CTop = RGB(TopB, TopG, TopR)
  881.       
  882.       LefR = 255: LefG = 255: LefB = 0
  883.       CLef = RGB(LefB, LefG, LefR)
  884.       
  885.       RitR = 128: RitG = 128: RitB = 128
  886.       CRit = RGB(RitB, RitG, RitB)
  887.       
  888.       BotR = 64: BotG = 64: BotB = 64
  889.       CBot = RGB(BotB, BotG, BotR)
  890.       STDiv = 45
  891.       MaxScaledTime = 350
  892.       imEmit.Left = W / 2
  893.    End Select
  894.    If aScroll Then cmdStart_Click
  895. End Sub
  896.  
  897. ' Control Angle
  898. Private Sub scrAngle_Scroll()
  899.    Call scrAngle_Change
  900. End Sub
  901. Private Sub scrAngle_Change()
  902. ' 70 - 110
  903. Dim S As Single
  904.    If Not aScroll Then Exit Sub
  905.    S = scrAngle.Value
  906.    S = S - 90  ' -20 to +20
  907.    LabAngle = Str$(S)
  908.    LabAngle.Refresh
  909.    S = -S
  910.    sAngle = S + 90
  911. End Sub
  912.  
  913. ' Control Speed
  914. Private Sub scrSpeed_Scroll()
  915.    Call scrSpeed_Change
  916. End Sub
  917. Private Sub scrSpeed_Change()
  918. ' 10 -> 90
  919. Dim i As Single
  920.    If Not aScroll Then Exit Sub
  921.    i = scrSpeed.Value / 20  ' .5 -> 4.5
  922.    LabSpeed = Str$(i)
  923.    LabSpeed.Refresh
  924.    MaxSpeed = i
  925. End Sub
  926.  
  927. ' Emitter
  928. Private Sub imEmit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  929.    imx = X
  930.    imy = Y
  931.    imMouseDown = True
  932. End Sub
  933.  
  934. Private Sub imEmit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  935. Dim NewX As Long
  936. Dim NewY As Long
  937.    If imMouseDown Then
  938.       ' Calculate new position
  939.       NewX = OldX + (X - imx) \ STX
  940.       If NewX < 0 Then
  941.          NewX = 0
  942.       ElseIf NewX > W - imEmit.Width Then
  943.          NewX = W - imEmit.Width
  944.       End If
  945.       imEmit.Left = NewX
  946.       OldX = NewX
  947.       ' Calculate new position
  948.       NewY = OldY + (Y - imy) \ STY
  949.       If NewY < 10 Then
  950.          NewY = 10
  951.       ElseIf NewY > H - imEmit.Height Then
  952.          NewY = H - imEmit.Height
  953.       End If
  954.       imEmit.Top = NewY
  955.       OldY = NewY
  956.    End If
  957. End Sub
  958.  
  959. Private Sub imEmit_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  960.    imMouseDown = False
  961. End Sub
  962.  
  963. ' Exit
  964. Private Sub mnuExit_Click()
  965.    aDone = True
  966.    StopPlay
  967.    Set tmr = Nothing
  968.    Unload Me
  969.    End
  970. End Sub
  971.  
  972. Private Sub Form_Unload(Cancel As Integer)
  973.    aDone = True
  974.    StopPlay
  975.    Set tmr = Nothing
  976.    Unload Me
  977.    End
  978. End Sub
  979.  
  980.  
  981.