Microsoft Small Basic

Program Listing: ZKQ845-0
' Turtle Polygon
' Version 0.2
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Program ID ZKQ845-0

Not = "True=False;False=True;"
GraphicsWindow.Title = "Turtle Polygon 0.2"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(10, 10, "Number of sides")
sides = Controls.AddTextBox(120, 8)
Controls.AddButton("Draw", 290, 6)
Controls.ButtonClicked = OnButtonClicked
GraphicsWindow.BrushColor = "Red"
error = Shapes.AddText("")
Shapes.Move(error, 10, 40)
first = "True"
While "True"
If buttonClicked Then
n1 = Controls.GetTextBoxText(sides)
If (3 <= n1) And (n1 <= 20) And (n1 = Math.Floor(n1)) Then
Shapes.SetText(error, "")
For j = 1 To 2
If j = 1 Then
GraphicsWindow.PenColor = "White"
GraphicsWindow.PenWidth = 4
Turtle.Speed = 10
Else
GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
GraphicsWindow.PenWidth = 2
Turtle.Speed = 9
n = n1
EndIf
If Not[first] Then
DrawPolygon()
EndIf
first = "False"
EndFor
Else
Shapes.SetText(error, "Illeagal number of sides.")
EndIf
buttonClicked = "False"
Else
Program.Delay(200)
EndIf
EndWhile

Sub DrawPolygon
' draw regular polygon
' param n - number of edges
r = 360 / n
a = 360 / n
For i = 1 To n
Turtle.Move(r)
Turtle.Turn(a)
EndFor
EndSub

Sub OnButtonClicked
buttonClicked = "True"
EndSub