Microsoft Small Basic

Program Listing: LBX119
' Draw Smile
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.
'
GraphicsWindow.Title = "Smile"
DrawGrid()
' face
GraphicsWindow.BrushColor = "Yellow"
GraphicsWindow.FillEllipse(315 - 200, 10, 400, 400)
' mouth
GraphicsWindow.PenWidth = 10
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "Black"
param = "x=315;y=200;r=150;a1=0;a2=180;da=5;ct=Round"
DrawArc()
' eyes
d = 30
GraphicsWindow.FillEllipse(250 - d / 2, 160 - 2 * d, d, 4 * d)
GraphicsWindow.FillEllipse(380 - d / 2, 160 - 2 * d, d, 4 * d)

Sub DrawArc
' param["x"] - center x coordinate [px]
' param["y"] - center y coordinate [px]
' param["r"] - radius [px]
' param["a1"] - start angle [°]
' param["a2"] - end angle [°]
' param["da"] - delta (step) angle [°]
' param["ct"] - cap type ("Round" for round, otherwise for flat)
Stack.PushValue("local", local)
Stack.PushValue("local", a)
local["pw"] = GraphicsWindow.PenWidth
local["bc"] = GraphicsWindow.BrushColor
GraphicsWindow.BrushColor = GraphicsWindow.PenColor
For a = param["a1"] To param["a2"] Step param["da"]
local["rad"] = Math.GetRadians(a)
local["x2"] = param["x"] + param["r"] * Math.Cos(local["rad"])
local["y2"] = param["y"] + param["r"] * Math.Sin(local["rad"])
If param["a1"] < a Then
GraphicsWindow.DrawLine(local["x1"], local["y1"], local["x2"], local["y2"])
EndIf
If ((param ["a1"] < a) And (a < param["a2"])) Or Text.ConvertToLowerCase(param["ct"]) = "round" Then
GraphicsWindow.PenWidth = 0
GraphicsWindow.FillEllipse(local["x2"] - local["pw"] / 2, local["y2"] - local["pw"] / 2, local["pw"], local["pw"])
GraphicsWindow.PenWidth = local["pw"]
EndIf
local["x1"] = local["x2"]
local["y1"] = local["y2"]
EndFor
GraphicsWindow.BrushColor = local["bc"]
a = Stack.PopValue("local")
local = Stack.PopValue("local")
EndSub

Sub DrawGrid
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = "Gray"
For y = 0 To gh Step 50
GraphicsWindow.DrawLine(0, y, gw, y)
EndFor
For x = 0 To gw Step 50
GraphicsWindow.DrawLine(x, 0, x, gh)
EndFor
EndSub