Microsoft Small Basic

Program Listing: SXS341
' Python
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Last update 2017-11-17

GraphicsWindow.Title = "Python"
color = "SteelBlue"
CreatePython()
While "True"
MovePython()
Program.Delay(100)
EndWhile

Sub CreatePython
x = 600
y = 200
a = 7
GraphicsWindow.BrushColor = color
GraphicsWindow.PenWidth = 0
p[1] = Shapes.AddEllipse(40, 20)
Shapes.Move(p[1], x - 30, y - 10)
GraphicsWindow.BrushColor = "Black"
p[2] = Shapes.AddEllipse(8, 8)
Shapes.Move(p[2], x - 20, y - 6)
GraphicsWindow.BrushColor = color
iMax = 30
For i = 3 To iMax
p[i] = Shapes.AddEllipse(14, 14)
xp = x + (i - 3) * 7
yp = y + a * Math.Sin((i - 3) / 2) - 7
Shapes.Move(p[i], xp, yp)
EndFor
iTail = iMax
ip = 3
EndSub

Sub MovePython
ip = ip - 1
x = x - 7
If x < -200 Then
dx = 600 - x
For i = 1 To iMax
xp = Shapes.GetLeft(p[i])
yp = Shapes.GetTop(p[i])
Shapes.Move(p[i], xp + dx, yp)
EndFor
x = x + dx
EndIf
xp = x
yp = y + a * Math.Sin((ip - 3) / 2)
Shapes.Move(p[1], Shapes.GetLeft(p[1]) - 7, yp - 10)
Shapes.Move(p[2], Shapes.GetLeft(p[2]) - 7, yp - 6)
Shapes.Move(p[iTail], xp, yp - 7)
iTail = iTail - 1
If iTail = 2 Then
iTail = iMax
EndIf
EndSub