home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / sorts / pixel.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-12  |  5.4 KB  |  150 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00000000&
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3195
  6.    ClientLeft      =   3690
  7.    ClientTop       =   1020
  8.    ClientWidth     =   4680
  9.    ForeColor       =   &H00FFFFFF&
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   213
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   312
  14.    Begin VB.Timer Timer2 
  15.       Interval        =   10
  16.       Left            =   3480
  17.       Top             =   1920
  18.    End
  19.    Begin VB.Timer Timer1 
  20.       Enabled         =   0   'False
  21.       Interval        =   10
  22.       Left            =   720
  23.       Top             =   2160
  24.    End
  25.    Begin VB.Label Label1 
  26.       BackStyle       =   0  'Transparent
  27.       Caption         =   "Planet Source"
  28.       BeginProperty Font 
  29.          Name            =   "Arial Narrow"
  30.          Size            =   14.25
  31.          Charset         =   0
  32.          Weight          =   700
  33.          Underline       =   0   'False
  34.          Italic          =   -1  'True
  35.          Strikethrough   =   0   'False
  36.       EndProperty
  37.       ForeColor       =   &H000080FF&
  38.       Height          =   285
  39.       Left            =   1680
  40.       TabIndex        =   0
  41.       Top             =   840
  42.       Width           =   1620
  43.    End
  44. Attribute VB_Name = "Form1"
  45. Attribute VB_GlobalNameSpace = False
  46. Attribute VB_Creatable = False
  47. Attribute VB_PredeclaredId = True
  48. Attribute VB_Exposed = False
  49. DefInt A-Z
  50. Private cacheLabel_Left
  51. Private cacheLabel_Top
  52. Private cacheLabel_Bottom
  53. Private cacheLabel_Right
  54. Private ArraySize As Long
  55. Private Sub Form_Load()
  56. cacheLabel_Left = Label1.Left
  57. cacheLabel_Right = (Label1.Left + Label1.Width)
  58. cacheLabel_Top = Label1.Top
  59. cacheLabel_Bottom = (Label1.Top + Label1.Height)
  60. maxx = Label1.Width                          'get label width
  61. maxy = Label1.Height + (Label1.Height / 2)   'get label height add extra height for flame
  62. ReDim new_flame(maxx, maxy)                  'resize array to label
  63. ReDim old_flame(maxx, maxy)
  64. ArraySize = (maxx * maxy) * Len(new_flame(0, 0)) 'Get size of array for fast copy
  65. End Sub
  66. Private Sub Timer1_Timer()
  67. 'This is the main timer,  Displays and updates the flame
  68. Dim x, y As Integer                           'store current x and y pos.
  69. Dim red As Integer, green As Integer, blue As Integer                  'store colours
  70. Dim c As Long, myHDC As Long
  71. Dim stimer As Long
  72. 'This part generates the flame :)
  73. stimer = gettickcount
  74. For lps = 1 To 20
  75. For x = 1 To maxx - 1
  76.     For y = 1 To maxy - 1
  77.     red = new_flame(x + 1, y).r             'Add up the surrounding red colours
  78.     red = red + new_flame(x - 1, y).r
  79.     red = red + new_flame(x, y + 1).r
  80.     red = red + new_flame(x, y - 1).r
  81.        
  82.     green = new_flame(x + 1, y).g           'Add up the surrounding green colours
  83.     green = green + new_flame(x - 1, y).g
  84.     green = green + new_flame(x, y + 1).g
  85.     green = green + new_flame(x, y - 1).g
  86.       
  87.     'uses the row above (y-1) to give the effect of moving up!
  88.     If old_flame(x, y - 1).c = 0 Then   'if pixel is part of flame update
  89.         tmp = (Rnd * Flame_Height)                      'pick a number from the air!
  90.         r = red \ 4 - (tmp)
  91.         If r > -1 Then
  92.            old_flame(x, y - 1).r = r
  93.         Else
  94.            old_flame(x, y - 1).r = 0
  95.         End If
  96.         g = (green \ 4) - (tmp + 8) ' Average the green and decrease the colour
  97.         If g > -1 Then
  98.            old_flame(x, y - 1).g = g
  99.         Else
  100.            old_flame(x, y - 1).g = 0
  101.         End If
  102.     End If
  103.     Next y
  104. Next x
  105. 'This loop Displays and updates the array
  106.   myHDC = hDC
  107. c = 0
  108. 'new_flame = old_flame     ' update array VB6 only code
  109. CopyMemory new_flame(0, 0).r, old_flame(0, 0).r, ArraySize 'update array
  110. For x = 1 To maxx
  111.    For y = 1 To maxy
  112. '     new_flame(X, Y).r = old_flame(X, Y).r     ' update array
  113. '     new_flame(X, Y).g = old_flame(X, Y).g
  114. '     new_flame(X, Y).b = old_flame(X, Y).b
  115. '     put the pixel!
  116.       
  117.       CopyMemory c, old_flame(x - 1, y).r, 3
  118.       SetPixel myHDC, cacheLabel_Left + x, cacheLabel_Top + y, c
  119. '     Me.PSet (Label1.Left + X, Label1.Top + Y - Int(Label1.Height / 2)), c 'RGB(new_flame(X - 1, Y).r, new_flame(X - 1, Y).g, new_flame(X - 1, Y).b)
  120.    Next y
  121. Next x
  122. MsgBox gettickcount - stimer
  123. End Sub
  124. Private Sub Timer2_Timer()
  125.     'This timer only initializes the array colours
  126.     For x = 1 To maxx
  127.      For y = 1 To maxy
  128.           If Point(Label1.Left + x, Label1.Top + Label1.Height - y) <> 0 Then ' is there any colour at this point
  129.            new_flame(x, maxy - y).r = 255   ' Set colour to Yellow
  130.            new_flame(x, maxy - y).g = 255
  131.            new_flame(x, maxy - y).b = 0
  132.            new_flame(x, maxy - y).c = True  ' Is a permenant colour
  133.           Else
  134.            new_flame(x, maxy - y).r = 0
  135.            new_flame(x, maxy - y).g = 0
  136.            new_flame(x, maxy - y).b = 0
  137.            new_flame(x, maxy - y).c = False ' Can be any colour
  138.           End If
  139.           
  140.           old_flame(x, maxy - y).r = new_flame(x, maxy - y).r  'old_flame=new_flame
  141.           old_flame(x, maxy - y).g = new_flame(x, maxy - y).g
  142.           old_flame(x, maxy - y).b = new_flame(x, maxy - y).b
  143.           old_flame(x, maxy - y).c = new_flame(x, maxy - y).c
  144.      Next y
  145.   Next x
  146.   Label1.Visible = False
  147.   Timer1.Enabled = True   ' Call the Fire brigade :)
  148.   Timer2.Enabled = False  ' Turn off the taps!
  149. End Sub
  150.