|
プログラム初心者です。
ランダムウォークを簡単な処理で作ってみました。
Sub randomwalk1()
Dim r As Integer
Dim c As Integer
Dim i As Integer
ActiveSheet.Cells.Clear
Randomize
Cells.RowHeight = 5
Cells.ColumnWidth = 0.5
r = 50
c = 50
Cells(r, c).Select
For i = 1 To 10000
i = Int(9 * Rnd() + 1)
If i = 1 Then
r = r + 1
c = c
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 2 Then
r = r + 1
c = c + 1
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 3 Then
r = r
c = c + 1
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 4 Then
r = r - 1
c = c + 1
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 5 Then
r = r - 1
c = c
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 6 Then
r = r - 1
c = c - 1
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 7 Then
r = r
c = c - 1
Cells(r, c).Interior.ColorIndex = 3
ElseIf i = 8 Then
r = r + 1
c = c - 1
Cells(r, c).Interior.ColorIndex = 3
Else
r = r
c = c
Cells(r, c).Interior.ColorIndex = 3
End If
Next i
End Sub
ここから壁に跳ね返る処理と重なる部分の色を変えていく処理を追加したいのですが分かりません。簡単な処理でやってみたいです。お願いします。
|
|