Microsoft Small Basic

Program Listing: LWB173
' N Pointed Star
' Version 0.1
' for Challenge of the Month - October/November 2015
' Copyright © 2015 Nonki Takahashi. The MIT License.
'
GraphicsWindow.Title = "N Pointed Star 0.1"
Init()
Form()
Controls.ButtonClicked = OnButtonClicked
While "True"
If clicked Then
If Controls.LastClickedButton = btnMove Then
angle = Controls.GetTextBoxText(tboxAngle)
If angle <> "" Then
DrawStar()
EndIf
Else
For n = 3 To nMax Step 2
a = 360 / n
b = (360 - a) / 4
angle = Math.Floor(2 * b * 100) / 100
DrawStar()
EndFor
EndIf
clicked = "False"
Else
Program.Delay(200)
EndIf
EndWhile
Sub DrawStar
' param angle
GraphicsWindow.Clear()
Form()
tx = Turtle.X
ty = Turtle.Y
Turtle.Move(100)
Turtle.Turn(angle)
p = 1
d["x"] = Math.Abs(Turtle.X - tx)
d["y"] = Math.Abs(Turtle.Y - ty)
While 1 <= d["x"] Or 1 <= d["y"]
Turtle.Move(100)
Turtle.Turn(angle)
p = p + 1
d["x"] = Math.Abs(Turtle.X - tx)
d["y"] = Math.Abs(Turtle.Y - ty)
If pMax < p Then
d = "" ' exit while
EndIf
EndWhile
If p <= pMax Then
log = log + "angle=" + angle + " -> " + p + " pointed" + CRLF
Controls.SetTextBoxText(tboxLog, log)
EndIf
EndSub
Sub Form
GraphicsWindow.DrawText(10, 16, "Angle")
tboxAngle = Controls.AddTextBox(50, 12)
btnMove = Controls.AddButton("Move", 220, 10)
Controls.AddButton("Auto", 270, 10)
tboxLog = Controls.AddMultiLineTextBox(10, 40)
Controls.SetSize(tboxLog, 200, 360)
Controls.SetTextBoxText(tboxLog, log)
Turtle.Show()
EndSub
Sub Init
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "#EEEEEE"
GraphicsWindow.BrushColor = "Black"
nMax = 20
pMax = 360
Turtle.Speed = 10
EndSub
Sub OnButtonClicked
clicked = "True"
EndSub