Microsoft Small Basic

Program Listing: RFV485
' Brownian motion
title = "Brownian Motion Simulation with Turtle - "
GraphicsWindow.Title = title
x0 = Turtle.X
y0 = Turtle.y
x1 = GraphicsWindow.Width
y1 = GraphicsWindow.Height
GraphicsWindow.PenColor = "LightGray"
GraphicsWindow.DrawLine(x0, 0, x0, y1)
GraphicsWindow.DrawLine(0, y0, x1, y0)
GraphicsWindow.PenColor = "Black"
Turtle.Speed = 10
angle = 360
distance = 1
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(340, 14, "Angle is from 1 to")
oAngle = Controls.AddTextBox(450, 10)
Controls.SetTextBoxText(oAngle, angle)
GraphicsWindow.DrawText(340, 44, "Distance is")
oDistance = Controls.AddTextBox(450, 40)
Controls.SetTextBoxText(oDistance, distance)
Controls.TextTyped = OnTextTyped
For i = 1 To 50000
GraphicsWindow.Title = title + i
Turtle.Angle = Math.GetRandomNumber(angle)
Turtle.Move(distance)
EndFor
Sub OnTextTyped
oLast = Controls.LastTypedTextBox
If oLast = oAngle Then
angle = Controls.GetTextBoxText(oAngle)
ElseIf oLast = oDistance Then
distance = Controls.GetTextBoxText(oDistance)
EndIf
EndSub