76 lines
4.9 KiB
Text
76 lines
4.9 KiB
Text
'This code will create a GUI Form to display the result
|
|
|
|
hGridView As GridView 'The display is on a GridView
|
|
iCol As Integer = 38 'Column start position
|
|
iRow As Integer = 30 'Row start position
|
|
|
|
Public Sub Form_show()
|
|
|
|
SetUpForm 'Run the SetUpForm routine
|
|
Go 'Run the Go routine
|
|
|
|
End
|
|
|
|
Public Sub Go() 'This is what does the work
|
|
Dim siDir As Short = 3 'Stores the Direction of the ant 0 = North, 1 = East, 2 = South ,3 = West
|
|
Dim siCount As Short 'Counter
|
|
|
|
Repeat 'Repeat loop
|
|
Inc siCount 'Increase siCount
|
|
If hGridView[iRow, iCol].background = -1 Then 'If the Background of the cell is white then..(Right turn)
|
|
hGridView[iRow, iCol].background = 0 'Make the Background black
|
|
siDir = Direction(siDir, True) 'Get the direction to turn
|
|
If siDir = 0 Then Dec iRow 'Decrease Row if facing North
|
|
If siDir = 1 Then Inc iCol 'Increase Column if facing East
|
|
If siDir = 2 Then Inc iRow 'Increase Row if facing South
|
|
If siDir = 3 Then Dec iCol 'Decrease Column if facing West
|
|
End If
|
|
'Wait 'This will allow you to see the Grid being populated. Rem it out for an instant result
|
|
If hGridView[iRow, iCol].background = 0 Then 'If the Background of the cell is black then.. Left Turn
|
|
hGridView[iRow, iCol].background = -1 'Make the Background white
|
|
siDir = Direction(siDir, False) 'Get the direction to turn
|
|
If siDir = 0 Then Dec iRow 'Decrease Row if facing North
|
|
If siDir = 1 Then Inc iCol 'Increase Column if facing East
|
|
If siDir = 2 Then Inc iRow 'Increase Row if facing South
|
|
If siDir = 3 Then Dec iCol 'Decrease Column if facing West
|
|
End If
|
|
Until siCount = 9660 'Loop 9660 times
|
|
|
|
End
|
|
|
|
Public Sub Direction(siDirection As Short, bWay As Boolean) As Byte 'To workout which way to go
|
|
|
|
If bWay Then 'If turning Right then
|
|
Inc siDirection 'Increase siDirection e.g. 0 = North to 1 = East
|
|
Else 'Else if turning Left
|
|
Dec siDirection 'Decrease siDirection e.g. 2 = South to 1 = East
|
|
End If
|
|
|
|
If siDirection < 0 Then siDirection = 3 'To address 0 - 1 = -1
|
|
If siDirection > 3 Then siDirection = 0 'To address 3 + 1 = 4
|
|
|
|
Return siDirection 'Return the correct direction
|
|
|
|
End
|
|
|
|
Public Sub SetUpForm() 'Set up the Form and Create the Gridview
|
|
|
|
With Me 'Change the Properties of the Form
|
|
.Height = 1012 'Set the Form Height
|
|
.Width = 1012 'Set the Form Width
|
|
.Arrangement = Arrange.Vertical 'Set the Form Arrangement
|
|
.Padding = 5 'Set the Form Padding (Border)
|
|
.title = "Langton's ant" 'Set the Form Title
|
|
End With
|
|
|
|
hGridView = New GridView(Me) 'Create a GridView
|
|
With hGridView 'Change the Properties of the GridView
|
|
.Columns.count = 100 'Create 100 Columns
|
|
.Rows.count = 100 'Create 100 Rows
|
|
.Columns.Width = 10 'Set the Column Width
|
|
.Rows.Height = 10 'Set the Column Height
|
|
.expand = True 'Set the Gridview to Expand to fill the Form
|
|
.background = -1 'Set the Gridview background to White
|
|
End With
|
|
|
|
End
|