Microsoft Small Basic

Program Listing: GMT047-1
' micro:bit
' Version 0.3
' Copyright © 2017-2019 Nonki Takahashi. The MIT License.
' 2017-08-28 16:15:18 Shapes generated by Shapes 2.3b.
' Last update 2019-04-29
' Program ID GMT047-1

SB_Workaround()
Init()
' initialize micro:bit shapes
Shapes_Init_Caption()
base = shY + 50
scale = 1
angle = 0
iMin = 1
iMax = Array.GetItemCount(shape)
Shapes_Add()
' initialize micro:bit shapes
Shapes_Init_Microbit()
scale = 1.6
iMax = Array.GetItemCount(shape)
Shapes_Add()
x = (gw - 166 * scale) / 2
y = (base - 146 * scale) / 2
Shapes_Move()
' turn off LEDs
FindLEDs()
For y = 0 To 4
For x = 0 To 4
OffLED()
EndFor
EndFor
FindButtons()
ax1 = Shapes.GetLeft(objButton["A"])
ay1 = Shapes.GetTop(objButton["A"])
bx1 = Shapes.GetLeft(objButton["B"])
by1 = Shapes.GetTop(objButton["B"])
bs = 10 * scale ' button size
ax2 = ax1 + bs - 1
ay2 = ay1 + bs - 1
bx2 = bx1 + bs - 1
by2 = by1 + bs - 1
GraphicsWindow.MouseDown = OnMouseDown
ms = Clock.ElapsedMilliseconds
While "True"
If 1000 < Clock.ElapsedMilliseconds - ms Then
ms = Clock.ElapsedMilliseconds
id = id + 1
If idMax < id Then
id = 1
EndIf
LoadIcon()
ShowLEDs()
EndIf
If mouseDown Then
If ax1 <= mx And mx <= ax2 And ay1 <= my And my <= ay2 Then
LoadA()
ShowLEDs()
angle = -1
Shapes_Rotate()
Program.Delay(200)
angle = 0
Shapes_Rotate()
ElseIf bx1 <= mx And mx <= bx2 And by1 <= my And my <= by2 Then
LoadB()
ShowLEDs()
angle = 1
Shapes_Rotate()
Program.Delay(200)
angle = 0
Shapes_Rotate()
EndIf
mouseDown = "False"
Else
Program.Delay(200)
EndIf
EndWhile

Sub Init
LF = Text.GetCharacter(10)
gw = 598
gh = 428
idMax = 40
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "micro:bit"
EndSub

Sub FindButtons
For i = iMin To iMax
shp = shape[i]
If Text.StartsWith(shp["name"], "button ") Then
bc = shp["bc"]
If bc = "#000000" Then
name = shp["name"]
ab = Text.GetSubText(name, 8, 1)
objButton[ab] = shp["obj"]
EndIf
EndIf
EndFor
EndSub

Sub FindLEDs
For i = iMin To iMax
shp = shape[i]
If Text.StartsWith(shp["name"], "LED ") Then
name = shp["name"]
x = Text.GetSubText(name, 5, 1)
y = Text.GetSubText(name, 7, 1)
objLED[x][y] = shp["obj"]
ElseIf Text.StartsWith(shp["name"], "Flare ") Then
name = shp["name"]
x = Text.GetSubText(name, 7, 1)
y = Text.GetSubText(name, 9, 1)
objFlare[x][y] = shp["obj"]
EndIf
EndFor
EndSub

Sub LoadA
img = "" + LF
img = img + " . # # . . " + LF
img = img + " # . . # . " + LF
img = img + " # # # # . " + LF
img = img + " # . . # . " + LF
img = img + " # . . # . " + LF
EndSub

Sub LoadB
img = "" + LF
img = img + " # # # . . " + LF
img = img + " # . . # . " + LF
img = img + " # # # . . " + LF
img = img + " # . . # . " + LF
img = img + " # # # . . " + LF
EndSub

Sub LoadIcon
img = "" + LF
If id = 1 Then ' heart
img = img + " . # . # . " + LF
img = img + " # # # # # " + LF
img = img + " # # # # # " + LF
img = img + " . # # # . " + LF
img = img + " . . # . . " + LF
ElseIf id = 2 Then ' small heart
img = img + " . . . . . " + LF
img = img + " . # . # . " + LF
img = img + " . # # # . " + LF
img = img + " . . # . . " + LF
img = img + " . . . . . " + LF
ElseIf id = 3 Then ' yes
img = img + " . . . . . " + LF
img = img + " . . . . # " + LF
img = img + " . . . # . " + LF
img = img + " # . # . . " + LF
img = img + " . # . . . " + LF
ElseIf id = 4 Then ' no
img = img + " # . . . # " + LF
img = img + " . # . # . " + LF
img = img + " . . # . . " + LF
img = img + " . # . # . " + LF
img = img + " # . . . # " + LF
ElseIf id = 5 Then ' happy
img = img + " . . . . . " + LF
img = img + " . # . # . " + LF
img = img + " . . . . . " + LF
img = img + " # . . . # " + LF
img = img + " . # # # . " + LF
ElseIf id = 6 Then ' sad
img = img + " . . . . . " + LF
img = img + " . # . # . " + LF
img = img + " . . . . . " + LF
img = img + " . # # # . " + LF
img = img + " # . . . # " + LF
ElseIf id = 7 Then ' confused
img = img + " . . . . . " + LF
img = img + " . # . # . " + LF
img = img + " . . . . . " + LF
img = img + " . # . # . " + LF
img = img + " # . # . # " + LF
ElseIf id = 8 Then ' angry
img = img + " # . . . # " + LF
img = img + " . # . # . " + LF
img = img + " . . . . . " + LF
img = img + " # # # # # " + LF
img = img + " # . # . # " + LF
ElseIf id = 9 Then ' asleep
img = img + " . . . . . " + LF
img = img + " # # . # # " + LF
img = img + " . . . . . " + LF
img = img + " . # # # . " + LF
img = img + " . . . . . " + LF
ElseIf id = 10 Then ' surprised
img = img + " . # . # . " + LF
img = img + " . . . . . " + LF
img = img + " . . # . . " + LF
img = img + " . # . # . " + LF
img = img + " . . # . . " + LF
ElseIf id = 11 Then ' silly
img = img + " # . . . # " + LF
img = img + " . . . . . " + LF
img = img + " # # # # # " + LF
img = img + " . . . # # " + LF
img = img + " . . . # # " + LF
ElseIf id = 12 Then ' fabulous
img = img + " # # # # # " + LF
img = img + " # # . # # " + LF
img = img + " . . . . . " + LF
img = img + " . # . # . " + LF
img = img + " . # # # . " + LF
ElseIf id = 13 Then ' meh
img = img + " # # . # # " + LF
img = img + " . . . . . " + LF
img = img + " . . . # . " + LF
img = img + " . . # . . " + LF
img = img + " . # . . . " + LF
ElseIf id = 14 Then ' t-shirt
img = img + " # # . # # " + LF
img = img + " # # # # # " + LF
img = img + " . # # # . " + LF
img = img + " . # # # . " + LF
img = img + " . # # # . " + LF
ElseIf id = 15 Then ' roller skate
img = img + " . . . # # " + LF
img = img + " . . . # # " + LF
img = img + " # # # # # " + LF
img = img + " # # # # # " + LF
img = img + " . # . # . " + LF
ElseIf id = 16 Then ' duck
img = img + " . # # . . " + LF
img = img + " # # # . . " + LF
img = img + " . # # # # " + LF
img = img + " . # # # . " + LF
img = img + " . . . . . " + LF
ElseIf id = 17 Then ' house
img = img + " . . # . . " + LF
img = img + " . # # # . " + LF
img = img + " # # # # # " + LF
img = img + " . # # # . " + LF
img = img + " . # . # . " + LF
ElseIf id = 18 Then ' tortoise
img = img + " . . . . . " + LF
img = img + " . # # # . " + LF
img = img + " # # # # # " + LF
img = img + " . # . # . " + LF
img = img + " . . . . . " + LF
ElseIf id = 19 Then ' butterfly
img = img + " # # . # # " + LF
img = img + " # # # # # " + LF
img = img + " . . # . . " + LF
img = img + " # # # # # " + LF
img = img + " # # . # # " + LF
ElseIf id = 20 Then ' stick figure
img = img + " . . # . . " + LF
img = img + " # # # # # " + LF
img = img + " . . # . . " + LF
img = img + " . # . # . " + LF
img = img + " # . . . # " + LF
ElseIf id = 21 Then ' ghost
img = img + " . # # # . " + LF
img = img + " # . # . # " + LF
img = img + " # # # # # " + LF
img = img + " # # # # # " + LF
img = img + " # . # . # " + LF
ElseIf id = 22 Then ' sword
img = img + " . . # . . " + LF
img = img + " . . # . . " + LF
img = img + " . . # . . " + LF
img = img + " . # # # . " + LF
img = img + " . . # . . " + LF
ElseIf id = 23 Then ' giraffe
img = img + " # # . . . " + LF
img = img + " . # . . . " + LF
img = img + " . # . . . " + LF
img = img + " . # # # . " + LF
img = img + " . # . # . " + LF
ElseIf id = 24 Then ' skull
img = img + " . # # # . " + LF
img = img + " # . # . # " + LF
img = img + " # # # # # " + LF
img = img + " . # # # . " + LF
img = img + " . # # # . " + LF
ElseIf id = 25 Then ' umbrella
img = img + " . # # # . " + LF
img = img + " # # # # # " + LF
img = img + " . . # . . " + LF
img = img + " # . # . . " + LF
img = img + " # # # . . " + LF
ElseIf id = 26 Then ' snake
img = img + " # # . . . " + LF
img = img + " # # . # # " + LF
img = img + " . # . # . " + LF
img = img + " . # # # . " + LF
img = img + " . . . . . " + LF
ElseIf id = 27 Then ' rabbit
img = img + " # . # . . " + LF
img = img + " # . # . . " + LF
img = img + " # # # # . " + LF
img = img + " # # . # . " + LF
img = img + " # # # # . " + LF
ElseIf id = 28 Then ' cow
img = img + " # . . . # " + LF
img = img + " # . . . # " + LF
img = img + " # # # # # " + LF
img = img + " . # # # . " + LF
img = img + " . . # . . " + LF
ElseIf id = 29 Then ' quater note
img = img + " . . # . . " + LF
img = img + " . . # . . " + LF
img = img + " . . # . . " + LF
img = img + " # # # . . " + LF
img = img + " # # # . . " + LF
ElseIf id = 30 Then ' eigth note
img = img + " . . # . . " + LF
img = img + " . . # # . " + LF
img = img + " . . # . # " + LF
img = img + " # # # . . " + LF
img = img + " # # # . . " + LF
ElseIf id = 31 Then ' pitchfork
img = img + " # . # . # " + LF
img = img + " # . # . # " + LF
img = img + " # # # # # " + LF
img = img + " . . # . . " + LF
img = img + " . . # . . " + LF
ElseIf id = 32 Then ' target
img = img + " . . # . . " + LF
img = img + " . # # # . " + LF
img = img + " # # . # # " + LF
img = img + " . # # # . " + LF
img = img + " . . # . . " + LF
ElseIf id = 33 Then ' triangle
img = img + " . . . . . " + LF
img = img + " . . # . . " + LF
img = img + " . # . # . " + LF
img = img + " # # # # # " + LF
img = img + " . . . . . " + LF
ElseIf id = 34 Then ' left triangle
img = img + " # . . . . " + LF
img = img + " # # . . . " + LF
img = img + " # . # . . " + LF
img = img + " # . . # . " + LF
img = img + " # # # # # " + LF
ElseIf id = 35 Then ' chess board
img = img + " . # . # . " + LF
img = img + " # . # . # " + LF
img = img + " . # . # . " + LF
img = img + " # . # . # " + LF
img = img + " . # . # . " + LF
ElseIf id = 36 Then ' diamond
img = img + " . . # . . " + LF
img = img + " . # . # . " + LF
img = img + " # . . . # " + LF
img = img + " . # . # . " + LF
img = img + " . . # . . " + LF
ElseIf id = 37 Then ' small diamond
img = img + " . . . . . " + LF
img = img + " . . # . . " + LF
img = img + " . # . # . " + LF
img = img + " . . # . . " + LF
img = img + " . . . . . " + LF
ElseIf id = 38 Then ' square
img = img + " # # # # # " + LF
img = img + " # . . . # " + LF
img = img + " # . . . # " + LF
img = img + " # . . . # " + LF
img = img + " # # # # # " + LF
ElseIf id = 39 Then ' small square
img = img + " . . . . . " + LF
img = img + " . # # # . " + LF
img = img + " . # . # . " + LF
img = img + " . # # # . " + LF
img = img + " . . . . . " + LF
ElseIf id = 40 Then ' scissors
img = img + " # # . . # " + LF
img = img + " # # . # . " + LF
img = img + " . . # . . " + LF
img = img + " # # . # . " + LF
img = img + " # # . . # " + LF
EndIf
EndSub

Sub OnMouseDown
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
mouseDown = "True"
EndSub

Sub ShowLEDs
p = 1
y = 0
x = 0
While p <= Text.GetLength(img)
c = Text.GetSubText(img, p, 1)
If c = "." Then
Shapes.HideShape(objFlare[x][y])
Shapes.HideShape(objLED[x][y])
ElseIf c = "#" Then
Shapes.ShowShape(objFlare[x][y])
Shapes.ShowShape(objLED[x][y])
EndIf
If Text.IsSubText(".#", c) THen
x = x + 1
If 4 < x Then
x = 0
y = y + 1
EndIf
EndIf
p = p + 1
EndWhile
EndSub

Sub OnLED
Shapes.ShowShape(objFlare[x][y])
Shapes.ShowShape(objLED[x][y])
EndSub

Sub OffLED
Shapes.HideShape(objFlare[x][y])
Shapes.HideShape(objLED[x][y])
EndSub

Sub Shapes_Init_Caption
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 362 ' x offset
shY = 358 ' y offset
shape = ""
shape[1] = "func=text;x=0;y=0;text=micro:bit;fs=50;fn=Trebuchet MS;bc=#DDDDDD;"
EndSub

Sub Shapes_Init_Microbit
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 210 ' x offset
shY = 130 ' y offset
shape = ""
shape[1] = "func=rect;x=8;y=0;width=150;height=8;bc=#000000;pw=0;name=top;"
shape[2] = "func=ell;x=0;y=0;width=16;height=16;bc=#00FF99;pw=0;name=corner;"
shape[3] = "func=ell;x=150;y=0;width=16;height=16;bc=#000000;pw=0;name=corner;"
shape[4] = "func=rect;x=0;y=8;width=166;height=110;bc=#000000;pw=0;name=board;"
shape[5] = "func=tri;x=-7;y=-3.5;x1=22;y1=0;x2=0;y2=22;x3=44;y3=22;bc=#00FF99;pw=0;angle=-45;"
shape[6] = "func=tri;x=-14.5;y=4.5;x1=22;y1=0;x2=0;y2=22;x3=44;y3=22;bc=#00FF99;pw=0;angle=-45;"
shape[7] = "func=tri;x=30;y=-1.7;x1=12;y1=0;x2=0;y2=12;x3=24;y3=12;bc=#00FF99;pw=0;angle=-45;"
shape[8] = "func=tri;x=52;y=-1;x1=6;y1=0;x2=0;y2=6;x3=12;y3=6;bc=#00FF99;pw=0;angle=-45;"
shape[9] = "func=ell;x=67;y=19;width=20;height=20;bc=#00FF99;pw=0;name=face;"
shape[10] = "func=ell;x=83;y=19;width=20;height=20;bc=#00FF99;pw=0;name=face;"
shape[11] = "func=rect;x=76;y=19;width=16;height=20;bc=#00FF99;pw=0;name=face;"
shape[12] = "func=rect;x=79;y=23;width=12;height=12;bc=#000000;pw=0;name=face;"
shape[13] = "func=line;x=77;y=25;x1=0;y1=0;x2=16;y2=0;pc=#000000;pw=4;name=face;"
shape[14] = "func=line;x=77;y=33;x1=0;y1=0;x2=16;y2=0;pc=#000000;pw=4;name=face;"
shape[15] = "func=ell;x=71;y=23;width=12;height=12;bc=#00FF99;pc=#000000;pw=4;name=eye;"
shape[16] = "func=ell;x=87;y=23;width=12;height=12;bc=#00FF99;pc=#000000;pw=4;name=eye;"
shape[17] = "func=rect;x=56;y=47;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[18] = "func=rect;x=54;y=47;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 0,0;"
shape[19] = "func=rect;x=56;y=49;width=4;height=7;bc=#FF6666;pw=0;name=LED 0,0;"
shape[20] = "func=rect;x=56;y=60;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[21] = "func=rect;x=54;y=60;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 0,1;"
shape[22] = "func=rect;x=56;y=62;width=4;height=7;bc=#FF6666;pw=0;name=LED 0,1;"
shape[23] = "func=rect;x=56;y=73;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[24] = "func=rect;x=54;y=73;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 0,2;"
shape[25] = "func=rect;x=56;y=75;width=4;height=7;bc=#FF6666;pw=0;name=LED 0,2;"
shape[26] = "func=rect;x=56;y=86;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[27] = "func=rect;x=54;y=86;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 0,3;"
shape[28] = "func=rect;x=56;y=88;width=4;height=7;bc=#FF6666;pw=0;name=LED 0,3;"
shape[29] = "func=rect;x=56;y=99;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[30] = "func=rect;x=54;y=99;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 0,4;"
shape[31] = "func=rect;x=56;y=101;width=4;height=7;bc=#FF6666;pw=0;name=LED 0,4;"
shape[32] = "func=rect;x=69;y=47;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[33] = "func=rect;x=67;y=47;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 1,0;"
shape[34] = "func=rect;x=69;y=49;width=4;height=7;bc=#FF6666;pw=0;name=LED 1,0;"
shape[35] = "func=rect;x=69;y=60;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[36] = "func=rect;x=67;y=60;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 1,1;"
shape[37] = "func=rect;x=69;y=62;width=4;height=7;bc=#FF6666;pw=0;name=LED 1,1;"
shape[38] = "func=rect;x=69;y=73;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[39] = "func=rect;x=67;y=73;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 1,2;"
shape[40] = "func=rect;x=69;y=75;width=4;height=7;bc=#FF6666;pw=0;name=LED 1,2;"
shape[41] = "func=rect;x=69;y=86;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[42] = "func=rect;x=67;y=86;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 1,3;"
shape[43] = "func=rect;x=69;y=88;width=4;height=7;bc=#FF6666;pw=0;name=LED 1,3;"
shape[44] = "func=rect;x=69;y=99;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[45] = "func=rect;x=67;y=99;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 1,4;"
shape[46] = "func=rect;x=69;y=101;width=4;height=7;bc=#FF6666;pw=0;name=LED 1,4;"
shape[47] = "func=rect;x=82;y=47;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[48] = "func=rect;x=80;y=47;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 2,0;"
shape[49] = "func=rect;x=82;y=49;width=4;height=7;bc=#FF6666;pw=0;name=LED 2,0;"
shape[50] = "func=rect;x=82;y=60;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[51] = "func=rect;x=80;y=60;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 2,1;"
shape[52] = "func=rect;x=82;y=62;width=4;height=7;bc=#FF6666;pw=0;name=LED 2,1;"
shape[53] = "func=rect;x=82;y=73;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[54] = "func=rect;x=80;y=73;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 2,2;"
shape[55] = "func=rect;x=82;y=75;width=4;height=7;bc=#FF6666;pw=0;name=LED 2,2;"
shape[56] = "func=rect;x=82;y=86;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[57] = "func=rect;x=80;y=86;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 2,3;"
shape[58] = "func=rect;x=82;y=88;width=4;height=7;bc=#FF6666;pw=0;name=LED 2,3;"
shape[59] = "func=rect;x=82;y=99;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[60] = "func=rect;x=80;y=99;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 2,4;"
shape[61] = "func=rect;x=82;y=101;width=4;height=7;bc=#FF6666;pw=0;name=LED 2,4;"
shape[62] = "func=rect;x=95;y=47;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[63] = "func=rect;x=93;y=47;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 3,0;"
shape[64] = "func=rect;x=95;y=49;width=4;height=7;bc=#FF6666;pw=0;name=LED 3,0;"
shape[65] = "func=rect;x=95;y=60;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[66] = "func=rect;x=93;y=60;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 3,1;"
shape[67] = "func=rect;x=95;y=62;width=4;height=7;bc=#FF6666;pw=0;name=LED 3,1;"
shape[68] = "func=rect;x=95;y=73;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[69] = "func=rect;x=93;y=73;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 3,2;"
shape[70] = "func=rect;x=95;y=75;width=4;height=7;bc=#FF6666;pw=0;name=LED 3,2;"
shape[71] = "func=rect;x=95;y=86;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[72] = "func=rect;x=93;y=86;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 3,3;"
shape[73] = "func=rect;x=95;y=88;width=4;height=7;bc=#FF6666;pw=0;name=LED 3,3;"
shape[74] = "func=rect;x=95;y=99;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[75] = "func=rect;x=93;y=99;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 3,4;"
shape[76] = "func=rect;x=95;y=101;width=4;height=7;bc=#FF6666;pw=0;name=LED 3,4;"
shape[77] = "func=rect;x=108;y=47;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[78] = "func=rect;x=106;y=47;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 4,0;"
shape[79] = "func=rect;x=108;y=49;width=4;height=7;bc=#FF6666;pw=0;name=LED 4,0;"
shape[80] = "func=rect;x=108;y=60;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[81] = "func=rect;x=106;y=60;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 4,1;"
shape[82] = "func=rect;x=108;y=62;width=4;height=7;bc=#FF6666;pw=0;name=LED 4,1;"
shape[83] = "func=rect;x=108;y=73;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[84] = "func=rect;x=106;y=73;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 4,2;"
shape[85] = "func=rect;x=108;y=75;width=4;height=7;bc=#FF6666;pw=0;name=LED 4,2;"
shape[86] = "func=rect;x=108;y=86;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[87] = "func=rect;x=106;y=86;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 4,3;"
shape[88] = "func=rect;x=108;y=88;width=4;height=7;bc=#FF6666;pw=0;name=LED 4,3;"
shape[89] = "func=rect;x=108;y=99;width=4;height=11;bc=#333333;pw=0;name=LED;"
shape[90] = "func=rect;x=106;y=99;width=8;height=11;bc=#99FF0000;pw=0;name=Flare 4,4;"
shape[91] = "func=rect;x=108;y=101;width=4;height=7;bc=#FF6666;pw=0;name=LED 4,4;"
shape[92] = "func=rect;x=6;y=60;width=18;height=18;bc=#808080;pw=0;name=button A;"
shape[93] = "func=ell;x=10;y=64;width=10;height=10;bc=#000000;pw=0;name=button A;"
shape[94] = "func=ell;x=7;y=61;width=4;height=4;bc=#885544;pw=0;name=button A;"
shape[95] = "func=ell;x=19;y=61;width=4;height=4;bc=#885544;pw=0;name=button A;"
shape[96] = "func=ell;x=7;y=73;width=4;height=4;bc=#885544;pw=0;name=button A;"
shape[97] = "func=ell;x=19;y=73;width=4;height=4;bc=#885544;pw=0;name=button A;"
shape[98] = "func=rect;x=142;y=60;width=18;height=18;bc=#808080;pw=0;name=button B;"
shape[99] = "func=ell;x=146;y=64;width=10;height=10;bc=#000000;pw=0;name=button B;"
shape[100] = "func=ell;x=143;y=61;width=4;height=4;bc=#885544;pw=0;name=button B;"
shape[101] = "func=ell;x=155;y=61;width=4;height=4;bc=#885544;pw=0;name=button B;"
shape[102] = "func=ell;x=143;y=73;width=4;height=4;bc=#885544;pw=0;name=button B;"
shape[103] = "func=ell;x=155;y=73;width=4;height=4;bc=#885544;pw=0;name=button B;"
shape[104] = "func=rect;x=0;y=130;width=166;height=8;bc=#000000;pw=0;name=bottom;"
shape[105] = "func=rect;x=8;y=138;width=150;height=8;bc=#000000;pw=0;name=bottom;"
shape[106] = "func=ell;x=0;y=130;width=16;height=16;bc=#000000;pw=0;name=corner;"
shape[107] = "func=ell;x=150;y=130;width=16;height=16;bc=#000000;pw=0;name=corner;"
shape[108] = "func=rect;x=0;y=118;width=6;height=12;bc=#000000;pw=0;name=gap;"
shape[109] = "func=rect;x=17;y=118;width=22;height=12;bc=#000000;pw=0;name=gap;"
shape[110] = "func=rect;x=50;y=118;width=27;height=12;bc=#000000;pw=0;name=gap;"
shape[111] = "func=rect;x=88;y=118;width=27;height=12;bc=#000000;pw=0;name=gap;"
shape[112] = "func=rect;x=126;y=118;width=22;height=12;bc=#000000;pw=0;name=gap;"
shape[113] = "func=rect;x=160;y=118;width=6;height=12;bc=#000000;pw=0;name=gap;"
shape[114] = "func=ell;x=3;y=114;width=18;height=18;bc=Transparent;pc=#BFA95A;pw=4;"
shape[115] = "func=rect;x=6;y=128;width=11;height=18;bc=#BFA95A;pw=0;name=port 0;"
shape[116] = "func=ell;x=36;y=114;width=18;height=18;bc=Transparent;pc=#BFA95A;pw=4;"
shape[117] = "func=rect;x=39;y=128;width=11;height=18;bc=#BFA95A;pw=0;name=port 1;"
shape[118] = "func=ell;x=74;y=114;width=18;height=18;bc=Transparent;pc=#BFA95A;pw=4;"
shape[119] = "func=rect;x=77;y=128;width=11;height=18;bc=#BFA95A;pw=0;name=port 2;"
shape[120] = "func=ell;x=112;y=114;width=18;height=18;bc=Transparent;pc=#BFA95A;pw=4;"
shape[121] = "func=rect;x=115;y=128;width=11;height=18;bc=#BFA95A;pw=0;name=port 3V;"
shape[122] = "func=ell;x=145;y=114;width=18;height=18;bc=Transparent;pc=#BFA95A;pw=4;"
shape[123] = "func=rect;x=148;y=128;width=11;height=18;bc=#BFA95A;pw=0;name=port GND;"
shape[124] = "func=tri;x=6;y=84;x1=8;y1=0;x2=0;y2=8;x3=16;y3=8;bc=#00FF99;pw=0;angle=135;name=tri;"
shape[125] = "func=text;x=12;y=83;text=A;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[126] = "func=tri;x=145;y=46;x1=8;y1=0;x2=0;y2=8;x3=16;y3=8;bc=#00FF99;pw=0;angle=-45;name=tri;"
shape[127] = "func=text;x=151;y=47;text=B;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[128] = "func=text;x=10;y=134;text=0;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[129] = "func=text;x=43;y=134;text=1;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[130] = "func=text;x=81;y=134;text=2;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[131] = "func=text;x=117;y=134;text=3V;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[132] = "func=text;x=148;y=134;text=GND;fs=6;fn=Trebuchet MS;bc=#000000;"
shape[133] = "func=rect;x=1;y=130;width=3;height=13;bc=#BFA95A;pw=0;"
shape[134] = "func=rect;x=19;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[135] = "func=rect;x=24;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[136] = "func=rect;x=29;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[137] = "func=rect;x=34;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[138] = "func=rect;x=52;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[139] = "func=rect;x=57;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[140] = "func=rect;x=62;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[141] = "func=rect;x=67;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[142] = "func=rect;x=72;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[143] = "func=rect;x=90;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[144] = "func=rect;x=95;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[145] = "func=rect;x=100;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[146] = "func=rect;x=105;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[147] = "func=rect;x=110;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[148] = "func=rect;x=128;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[149] = "func=rect;x=133;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[150] = "func=rect;x=138;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[151] = "func=rect;x=143;y=130;width=3;height=16;bc=#BFA95A;pw=0;"
shape[152] = "func=rect;x=161;y=130;width=3;height=13;bc=#BFA95A;pw=0;"
shape[153] = "func=tri;x=0.879;y=142.379;x1=2.121;y1=0;x2=0;y2=2.121;x3=4.242;y3=2.121;bc=#BFA95A;pw=0;angle=45;"
shape[154] = "func=tri;x=159.879;y=142.379;x1=2.121;y1=0;x2=0;y2=2.121;x3=4.242;y3=2.121;bc=#BFA95A;pw=0;angle=-45;"
EndSub

Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
ElseIf x = 0 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub

Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param shp - current shape
' param x, y - original coordinate
' param alpha - angle [radian]
' returns x, y - workaround coordinate
If shp["func"] = "tri" Then
x1 = -Math.Floor(shp["x3"] / 2)
y1 = -Math.Floor(shp["y3"] / 2)
ElseIf shp["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shp["x1"] - shp["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shp["y1"] - shp["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub

Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub

Sub Shapes_Add
' Shapes | add shapes as shapes data
' param iMin, iMax - shape indices to add
' param shape - array of shapes
' param scale - 1 if same scale
' return shWidth, shHeight - total size of shapes
' return shAngle - current angle of shapes
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Shapes_CalcWidthAndHeight()
s = scale
For i = iMin To iMax
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
shAngle = 0
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub

Sub Shapes_CalcRotatePos
' Shapes | Calculate position for rotated shape
' param["x"], param["y"] - position of a shape
' param["width"], param["height"] - size of a shape
' param ["cx"], param["cy"] - center of rotation
' param ["angle"] - rotate angle
' return x, y - rotated position of a shape
_cx = param["x"] + param["width"] / 2
_cy = param["y"] + param["height"] / 2
x = _cx - param["cx"]
y = _cy - param["cy"]
Math_CartesianToPolar()
a = a + param["angle"]
x = r * Math.Cos(a * Math.Pi / 180)
y = r * Math.Sin(a * Math.Pi / 180)
_cx = x + param["cx"]
_cy = y + param["cy"]
x = _cx - param["width"] / 2
y = _cy - param["height"] / 2
EndSub

Sub Shapes_CalcWidthAndHeight
' Shapes | Calculate total width and height of shapes
' param iMin, iMax - shape indices to add
' return shWidth, shHeight - total size of shapes
For i = iMin To iMax
shp = shape[i]
If shp["func"] = "tri" Or shp["func"] = "line" Then
xmin = shp["x1"]
xmax = shp["x1"]
ymin = shp["y1"]
ymax = shp["y1"]
If shp["x2"] < xmin Then
xmin = shp["x2"]
EndIf
If xmax < shp["x2"] Then
xmax = shp["x2"]
EndIf
If shp["y2"] < ymin Then
ymin = shp["y2"]
EndIf
If ymax < shp["y2"] Then
ymax = shp["y2"]
EndIf
If shp["func"] = "tri" Then
If shp["x3"] < xmin Then
xmin = shp["x3"]
EndIf
If xmax < shp["x3"] Then
xmax = shp["x3"]
EndIf
If shp["y3"] < ymin Then
ymin = shp["y3"]
EndIf
If ymax < shp["y3"] Then
ymax = shp["y3"]
EndIf
EndIf
shp["width"] = xmax - xmin
shp["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shp["x"] + shp["width"]
shHeight = shp["y"] + shp["height"]
Else
If shWidth < shp["x"] + shp["width"] Then
shWidth = shp["x"] + shp["width"]
EndIf
If shHeight < shp["y"] + shp["height"] Then
shHeight = shp["y"] + shp["height"]
EndIf
EndIf
shape[i] = shp
EndFor
EndSub

Sub Shapes_Move
' Shapes | Move shapes
' param iMin, iMax - shape indices to add
' param shape - array of shapes
' param scale - to zoom
' param x, y - position to move
' return shX, shY - new position of shapes
Stack.PushValue("local", i)
s = scale
shX = x
shY = y
For i = iMin To iMax
shp = shape[i]
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], shX + _x * s, shY + _y * s)
EndFor
i = Stack.PopValue("local")
EndSub

Sub Shapes_Remove
' Shapes | Remove shapes
' param iMin, iMax - shapes indices to remove
' param shape - array of shapes
Stack.PushValue("local", i)
For i = iMin To iMax
shp = shape[i]
Shapes.Remove(shp["obj"])
EndFor
i = Stack.PopValue("local")
EndSub

Sub Shapes_Rotate
' Shapes | Rotate shapes
' param iMin, iMax - shapes indices to rotate
' param shape - array of shapes
' param cx, cy - rotation center
' param scale - to zoom
' param angle - to rotate
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
s = scale
param["angle"] = angle
If cx <> "" Then
param["cx"] = cx
Else
cx = "" ' to avoid syntax error
param["cx"] = shWidth / 2
EndIf
If cy <> "" Then
param["cy"] = cy
Else
cy = "" ' to avoid syntax error
param["cy"] = shHeight / 2
EndIf
For i = iMin To iMax
shp = shape[i]
param["x"] = shp["x"]
param["y"] = shp["y"]
param["width"] = shp["width"]
param["height"] = shp["height"]
Shapes_CalcRotatePos()
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(angle + shp["angle"])
SB_RotateWorkAround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
Shapes.Rotate(shp["obj"], angle + shp["angle"])
shape[i] = shp
EndFor
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub