home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Matrix
- AutoRedraw = -1 'True
- BorderStyle = 1 'Fixed Single
- Caption = "Mini Life"
- ClientHeight = 2985
- ClientLeft = 1080
- ClientTop = 1770
- ClientWidth = 3000
- Height = 3675
- Icon = LIFE.FRX:0000
- Left = 1020
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 2985
- ScaleWidth = 3000
- Top = 1140
- Width = 3120
- Begin PictureBox Picture1
- Height = 255
- Index = 64
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 63
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 63
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 62
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 62
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 61
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 61
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 60
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 60
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 59
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 59
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 58
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 58
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 57
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 57
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 56
- Top = 2640
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 56
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 55
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 55
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 54
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 54
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 53
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 53
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 52
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 52
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 51
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 51
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 50
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 50
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 49
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 49
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 48
- Top = 2280
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 48
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 47
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 47
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 46
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 46
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 45
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 45
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 44
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 44
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 43
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 43
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 42
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 42
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 41
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 41
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 40
- Top = 1920
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 40
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 39
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 39
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 38
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 38
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 37
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 37
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 36
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 36
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 35
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 35
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 34
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 34
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 33
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 33
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 32
- Top = 1560
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 32
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 31
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 31
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 30
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 30
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 29
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 29
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 28
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 28
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 27
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 27
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 26
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 26
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 25
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 25
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 24
- Top = 1200
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 24
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 23
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 23
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 22
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 22
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 21
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 21
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 20
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 20
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 19
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 19
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 18
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 18
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 17
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 17
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 16
- Top = 840
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 16
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 15
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 15
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 14
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 14
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 13
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 13
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 12
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 12
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 11
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 11
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 10
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 10
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 9
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 9
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 8
- Top = 480
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 8
- Left = 2640
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 7
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 7
- Left = 2280
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 6
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 6
- Left = 1920
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 5
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 5
- Left = 1560
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 4
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 4
- Left = 1200
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 3
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 3
- Left = 840
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 2
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 2
- Left = 480
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 1
- Top = 120
- Width = 255
- End
- Begin PictureBox Picture1
- Height = 255
- Index = 1
- Left = 120
- ScaleHeight = 225
- ScaleWidth = 225
- TabIndex = 0
- Top = 120
- Width = 255
- End
- Begin Menu MenuFile
- Caption = "&File"
- Begin Menu FileExit
- Caption = "E&xit"
- End
- End
- Begin Menu MenuRun
- Caption = "&Restart"
- Enabled = 0 'False
- End
- Dim LifeState(64) As Integer
- Sub FileExit_Click ()
- End
- End Sub
- Sub Form_Load ()
- 'Sets the cellular automata matrix to an initial random (50%) state of existence.
- Randomize
- CurrentColor = QBColor(Int(Rnd * 16)) 'Add some variety to the initial color
- For I% = 1 To 64
- Picture1(I%).backcolor = CurrentColor 'Sets the cell color for the initial state
- Picture1(I%).Visible = -1 * CInt((Rnd))
- Next I%
- End Sub
- Sub Form_Resize ()
- Main
- End Sub
- Sub Main ()
- 'The real action is here.
- 'The "Game of Life" rules are public domain.
- 'This Visual Basic adaptation by Rick Wagner (CIS 76427,2611) is given to the public by the author.
- 'Thanks to all the MSLANG Forum Visual Basic section who have uploaded code or given assistance
- 'through messages.
- 'The form for this sample/demo was created with an 800 x 600 16 color machine. Please let me
- 'know if there are problems with the form at other resolutions. I know I have to redo forms
- 'for 8414/A because of 1) system fonts are different and 2) bitmaps are smaller. There are
- 'none of those in this sample, but I moved the project window over so VGA types can see it.
- 'This sample program exhibits all the classic forms of the "Game of Life:" blinkers, squares, etc.
- 'Expanding the picture box array size and applying this code to it should work fine.
- 'Note: To implement really large matrices you may find better performance in using a pair of 2D integer arrays to
- ' hold alternating state vectors for the matrix, one for the current generation, one for the next.
- ' Using 2D matrices will make dealing with "ghost" cells easier.
- MenuRun.Enabled = -1 'Enables the "Restart" menu option
- Do While Flag% = 0 'Flag turns true when all cells are dead.
- CurrentColor = QBColor(Int(Rnd * 16)) 'Add some variety to the colors, and trace the loop visually.
- np% = DoEvents() 'Lemme outta here... (otherwise you get a real secure system).
- 'This loop establishes the sums of living neighbors for each cell
- 'and assigns future (next cycle) life states based on the "Game of Life" rules.
- For I% = 1 To 64 'A small (8 x 8) matrix implemented with a one dimensional control array.
- SumNeighbs% = 0 'Initialize the sum of neighbors (non-border cells can have 8 neighbors).
- If I% - 9 > 0 Then 'These conditions exclude nonexistent picture boxes.
- If Picture1(I% - 9).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% - 8 > 0 Then
- If Picture1(I% - 8).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% - 7 > 0 And Int(I% / 8) <> I% / 8 Then 'Excludes from right column cells the touch of ghosts
- If Picture1(I% - 7).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% - 1 > 0 And Int((I% + 7) / 8) <> (I% + 7) / 8 Then 'Exclude from left column cells the touch of ghosts
- If Picture1(I% - 1).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% + 1 < 65 And Int(I% / 8) <> I% / 8 Then 'Excludes from right
- If Picture1(I% + 1).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% + 7 < 65 And Int((I% + 7) / 8) <> (I% + 7) / 8 Then 'Excludes from left
- If Picture1(I% + 7).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% + 8 < 65 And Int((I% + 7) / 8) <> (I% + 7) / 8 Then 'Excldes from left
- If Picture1(I% + 8).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- If I% + 9 < 65 And Int(I% / 8) <> I% / 8 Then 'Excludes from right
- If Picture1(I% + 9).Visible = -1 Then SumNeighbs% = SumNeighbs% + 1
- End If
- 'These are the "Game of Life" rules:
- If SumNeighbs% < 2 Then LifeState(I%) = 0
- If SumNeighbs% = 2 And Picture1(I%).Visible = -1 Then LifeState(I%) = -1
- If SumNeighbs% = 2 And Picture1(I%).Visible = 0 Then LifeState(I%) = 0
- If SumNeighbs% = 3 Then LifeState(I%) = -1
- If SumNeighbs% > 3 Then LifeState(I%) = 0
- Next I%
- np% = DoEvents()
- 'This loop assigns visibility (aliveness) depending on states assigned above.
- SumStates% = 0 'Used to detect total death
- For I% = 1 To 64
- Picture1(I%).backcolor = CurrentColor 'Sets the cell color for the current cycle
- If LifeState(I%) = -1 Then
- Picture1(I%).Visible = -1
- Else Picture1(I%).Visible = 0
- End If
- SumStates% = SumStates% - LifeState(I%)
- Next I%
- If SumStates% = 0 Then Flag% = -1
- Loop
- MsgBox "They're all dead!"
- End Sub
- Sub MenuRun_Click ()
- 'Turn 'em all off to make the initialization look plainer.
- For I% = 1 To 64
- Picture1(I%).Visible = 0
- Next I%
- 'Set the cellular automata matrix to a random (50%) state of existence.
- For I% = 1 To 64
- Picture1(I%).Visible = -1 * CInt((Rnd))
- Next I%
- Main
- End Sub
-