Microsoft Small Basic

Program Listing: GDD223
' Turtle Tartan
' Copyright © 2019 Nonki Takahashi. The MIT License.

GraphicsWindow.Title = "Turtle Tartan"
Init()
' horizontal pattern
Turtle.Angle = -135
GraphicsWindow.PenWidth = 2
For i = 0 To gw + gh Step 4
j = 1
x1 = i
y1 = 0
ymax = i
GraphicsWindow.PenColor = pattern[j]["color"]
y = pattern[j]["width"]
If ymax < y Then
y = ymax
EndIf
While y <= ymax
y2 = y
x2 = x1 - (y2 - y1)
DrawLine()
If y < ymax Then
x1 = x2
y1 = y2
j = j + 1
If Array.GetItemCount(pattern) < j Then
j = 1
EndIf
y = y + pattern[j]["width"]
If ymax < y Then
y = ymax
EndIf
GraphicsWindow.PenColor = pattern[j]["color"]
Else
y = ymax + 1
EndIf
EndWhile
EndFor
' vertical pattern
Turtle.Angle = 45
GraphicsWindow.PenWidth = 1
For i = 2 To gw + gh Step 4
j = 1
x1 = 0
y1 = i
xmax = i
GraphicsWindow.PenColor = pattern[j]["color"]
x = pattern[j]["width"]
If xmax < x Then
x = xmax
EndIf
While x <= xmax
x2 = x
y2 = y1 - (x2 - x1)
DrawLine()
If x < xmax Then
x1 = x2
y1 = y2
j = j + 1
If Array.GetItemCount(pattern) < j Then
j = 1
EndIf
x = x + pattern[j]["width"]
If xmax < x Then
x = xmax
EndIf
GraphicsWindow.PenColor = pattern[j]["color"]
Else
x = xmax + 1
EndIf
EndWhile
EndFor

Sub DrawLine
Turtle.X = x2
Turtle.Y = y2
GraphicsWindow.DrawLine(x1, y1, x2, y2)
Program.Delay(1)
EndSub

Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "#222222"
Turtle.Show()
Turtle.PenUp()
pattern[1] = "width=20;color=Black;"
pattern[2] = "width=23;color=Teal;"
pattern[3] = "width=2;color=Black;"
pattern[4] = "width=4;color=DarkRed;"
pattern[5] = "width=2;color=Black;"
pattern[6] = "width=23;color=Teal;"
pattern[7] = "width=20;color=Black;"
pattern[8] = "width=25;color=SeaGreen;"
pattern[9] = "width=4;color=Gold;"
pattern[10] = "width=25;color=SeaGreen;"
pattern[11] = "width=20;color=Black;"
pattern[12] = "width=4;color=Teal;"
pattern[13] = "width=4;color=Black;"
pattern[14] = "width=4;color=Teal;"
pattern[15] = "width=4;color=Black;"
pattern[16] = "width=12;color=Teal;"
pattern[17] = "width=4;color=DarkRed;"
pattern[18] = "width=12;color=Teal;"
pattern[19] = "width=4;color=Black;"
pattern[20] = "width=4;color=Teal;"
pattern[21] = "width=4;color=Black;"
pattern[22] = "width=4;color=Teal;"
pattern[23] = "width=20;color=Black;"
pattern[24] = "width=25;color=SeaGreen;"
pattern[25] = "width=4;color=Gold;"
pattern[26] = "width=25;color=SeaGreen;"
EndSub