Microsoft Small Basic

Program Listing: SFF730-7
' Happy Birthday Small Basic!!
' The 12th Anniversary
' Copyright c 2014-2020 Nonki Takahashi. The MIT License.
' 2014-10-23 20:26:31 Shapes generated by Shapes 1.7b.
' Last update 2020-10-21
' Program ID SFF730-7

anniv = "12th"
SB_Workaround()
Init()
' initialize shapes
Shapes_Init_Cake()
' add shapes
scale = 1
angle = 0
name = "Cake"
SBO_SplitShape()
Sprite_Add()
CalcCenter()
Sprite_Move()
Shapes_Init_Logo()
name = "Logo"
SBO_SplitShape()
Sprite_Add()
CalcCenter()
Sprite_Move()
' draw Happy Birthday Small Basic!!
GraphicsWindow.FontSize = 24
GraphicsWindow.BrushColor = "White"
x = (gw - 392) / 2
y = gh * 70 / 441
caption = Shapes.AddText("Happy " + anniv + " Birthday Small Basic!!")
Shapes.Move(caption, x, y)
GraphicsWindow.PenWidth = 0
AddTickerTape()
Timer.Interval = dt * 1000
Timer.Tick = OnTick

Sub AddTickerTape
nMax = nMax + 1
_r = Math.GetRandomNumber(128) + 127
_g = Math.GetRandomNumber(128) + 127
_b = Math.GetRandomNumber(128) + 127
GraphicsWindow.BrushColor = GraphicsWindow.GetColorFromRGB(_r, _g, _b)
tt[nMax] = Shapes.AddRectangle(16, 8)
x[nMax] = Math.GetRandomNumber(gw - 20) + 10
y[nMax] = -10
a[nMax] = Math.GetRandomNumber(360) - 1
Shapes.Rotate(tt[nMax], a[nMax])
Shapes.Move(tt[nMax], x[nMax], y[nMax])
EndSub

Sub CalcCenter
i = nSprite
spr = sprite[i]
width = spr["width"]
height = spr["height"]
x = Math.Floor((gw - width) / 2)
y = Math.Floor((gh - height) / 2)
EndSub

Sub Init
colors = "0=#88FFAA;30=#66CC88;50=#449966;70=#226644;100=#003322;"
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
GraphicsWindow.BackgroundColor = "#449966"
If sbd Then
' fill background
param = "x=0;y=0;width=" + gw + ";height=" + gh + ";angle=40;"
param = param + colors
SBO_SplitParam()
GW_FillLinearGradientRectangle()
EndIf
' draw the age
GraphicsWindow.FontName = "Arial"
GraphicsWindow.FontSize = 500
If sbd Then
GraphicsWindow.BrushColor = "#33000000"
Else
GraphicsWindow.BrushColor = "#00000033"
EndIf
x = (gw - 556) / 2
y = gh / 2 - 280
GraphicsWindow.DrawText(x, y, Text.GetSubText(anniv, 1, 2))
dt = 0.2 ' sec
EndSub

Sub OnTick
UpdateTickerTape()
EndSub

Sub UpdateTickerTape
If Math.GetRandomNumber(10) = 1 Then
AddTickerTape()
EndIf
For i = nMin To nMax
x[i] = x[i] + Math.GetRandomNumber(4) - 2
y[i] = y[i] + Math.GetRandomNumber(4)
If y[i] > gh + 60 Then
Shapes.Remove(tt[i])
nMin = i + 1
EndIf
Shapes.Move(tt[i], x[i], y[i])
a[i] = a[i] + 45
If a[i] >= 360 Then
a[i] = a[i] - 360
EndIf
Shapes.Zoom(tt[i], 1, Math.Sin(Math.GetRadians(a[i])))
EndFor
EndSub

Sub Color_ColorToRGB
' Color | Convert Color to RGB
' param c - color
' returns r, g, b - red, green and blue values
If Text.StartsWith(c, "#") Then
c = Text.ConvertToUpperCase(c)
Else
_pc = GraphicsWindow.PenColor
GraphicsWindow.PenColor = c
c = GraphicsWindow.PenColor
GraphicsWindow.PenColor = _pc
EndIf
sHex = Text.GetSubText(c, 2, 2)
Math_Hex2Dec()
r = iDec
sHex = Text.GetSubText(c, 4, 2)
Math_Hex2Dec()
g = iDec
sHex = Text.GetSubText(c, 6, 2)
Math_Hex2Dec()
b = iDec
EndSub

Sub Color_PercentToRGB
' Color | Convert Percent to RGB
' param percent - percent
' param color[] - color table indexed percent
' param n - item count of color[]
' param index[] - all indices of color[]
For i = 1 To n
p1 = index[i]
If index[i] = percent Then
p2 = index[i]
i = n + 1 ' break
ElseIf index[i] < percent And percent < index[i + 1] Then
p2 = index[i + 1]
i = n + 1 ' break
EndIf
EndFor
c = color[p1]
Color_ColorToRGB()
If p1 <> p2 Then
r1 = r
g1 = g
b1 = b
c = color[p2]
Color_ColorToRGB()
r2 = r
g2 = g
b2 = b
r = Math.Floor(r1 + (r2 - r1) * (percent - p1) / (p2 - p1))
g = Math.Floor(g1 + (g2 - g1) * (percent - p1) / (p2 - p1))
b = Math.Floor(b1 + (b2 - b1) * (percent - p1) / (p2 - p1))
EndIf
EndSub

Sub Color_NameToColor
' Color | convert color name to color
' param c - color name
' returns c -"#rrggbb"
If Text.StartsWith(c, "#") And 6 < Text.GetLength(c) Then
c = Text.ConvertToUpperCase(c)
Else
Stack.PushValue("local", GraphicsWindow.PenColor)
GraphicsWindow.PenColor = c
c = GraphicsWindow.PenColor
GraphicsWindow.PenColor = Stack.PopValue("local")
EndIf
EndSub

Sub GW_DrawLine
' GraphicsWindow | draw line
' param r, g, b - red, green blue
' param angle
' param x1, y1, x2, y2 - edges of line
GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(r, g, b)
If 0 <= angle And angle < 45 Then
GraphicsWindow.DrawLine(x1 + x0, y1 + y0, x2 + x0, y2 + y0)
ElseIf 45 <= angle And angle < 90 Then
GraphicsWindow.DrawLine(y1 + x0, x1 + y0, y2 + x0, x2 + y0)
ElseIf 90 <= angle And angle < 135 Then
GraphicsWindow.DrawLine(-y1 + x0 + width, x1 + y0, -y2 + x0 + width, x2 + y0)
ElseIf 135 <= angle And angle < 180 Then
GraphicsWindow.DrawLine(-x1 + x0 + width, y1 + y0, -x2 + x0 + width, y2 + y0)
ElseIf 180 <= angle And angle < 225 Then
GraphicsWindow.DrawLine(-x1 + x0 + width, -y1 + y0 + height, -x2 + x0 + width, -y2 + y0 + height)
ElseIf 225 <= angle And angle < 270 Then
GraphicsWindow.DrawLine(-y1 + x0 + width, -x1 + y0 + height, -y2 + x0 + width, -x2 + y0 + height)
ElseIf 270 <= angle And angle < 315 Then
GraphicsWindow.DrawLine(y1 + x0, -x1 + y0 + height, y2 + x0, -x2 + y0 + height)
ElseIf 315 <= angle And angle < 360 Then
GraphicsWindow.DrawLine(x1 + x0, -y1 + y0 + height, x2 + x0, -y2 + y0 + height)
EndIf
Program.Delay(1)
EndSub

Sub GW_FillLinearGradientRectangle
' GraphicsWindow | fill linear gradient rectangle
' param["x"], param["y"] - position of the rectangle
' param["width"], param["height"] - size of the rectangle
' param["angle"] - angle of gradient
' param["0"]..param["100"] - 0% to 100% colors
x0 = param["x"]
y0 = param["y"]
width = param["width"]
height = param["height"]
angle = param["angle"]
n = Array.GetItemCount(param)
index = Array.GetAllIndices(param)
color = ""
For i = 1 To n
If index[i] + 0 = index[i] And 0 <= index[i] And index[i] <= 100 Then
c = param[index[i]]
Color_NameToColor()
color[index[i]] = c
EndIf
EndFor
If color[0] = "" Then
color[0] = GraphicsWindow.BrushColor
EndIf
If color[100] = "" Then
color[100] = GraphicsWindow.BrushColor
EndIf
n = Array.GetItemCount(color)
index = Array.GetAllIndices(color)
a45 = Math.Remainder(angle, 45)
If 0 <= angle And angle < 45 Then
w45 = width
h45 = height
ElseIf 45 <= angle And angle < 90 Then
w45 = height
h45 = width
a45 = 45 - a45
ElseIf 90 <= angle And angle < 135 Then
w45 = height
h45 = width
ElseIf 135 <= angle And angle < 180 Then
w45 = width
h45 = height
a45 = 45 - a45
ElseIf 180 <= angle And angle < 225 Then
w45 = width
h45 = height
ElseIf 225 <= angle And angle < 270 Then
w45 = height
h45 = width
a45 = 45 - a45
ElseIf 270 <= angle And angle < 315 Then
w45 = height
h45 = width
ElseIf 315 <= angle And angle < 360 Then
w45 = width
h45 = height
a45 = 45 - a45
EndIf
If a45 = 0 Then
For x = 0 To w45
percent = Math.Floor(x * 100 / w45)
Color_PercentToRGB()
x1 = x
y1 = 0
x2 = x
y2 = h45
GW_DrawLine()
EndFor
ElseIf 0 < a45 And a45 <= 45 Then
tan = Math.Tan(Math.GetRadians(a45))
If h45 <= w45 Then
dx = Math.Floor(h45 * tan)
For x = 0 To dx
percent = Math.Floor(x * 100 / (w45 + dx))
Color_PercentToRGB()
x1 = x
y1 = 0
x2 = 0
y2 = Math.Floor(x / tan)
GW_DrawLine()
EndFor
For x = dx To w45
percent = Math.Floor(x * 100 / (w45 + dx))
Color_PercentToRGB()
x1 = x
y1 = 0
x2 = x - dx
y2 = h45
GW_DrawLine()
EndFor
For x = w45 To w45 + dx
percent = Math.Floor(x * 100 / (w45 + dx))
Color_PercentToRGB()
x1 = x - dx
y1 = h45
x2 = w45
y2 = Math.Floor((x - w45) / tan)
GW_DrawLine()
EndFor
Else ' width < height
dx = Math.Floor(h45 * tan - w45)
dy = Math.Floor(w45 / tan)
For x = 0 To w45
percent = Math.Floor(x * 100 / (2 * w45 + dx))
Color_PercentToRGB()
x1 = x
y1 = 0
x2 = 0
y2 = Math.Floor(x / tan)
GW_DrawLine()
EndFor
For x = 0 To dx
percent = Math.Floor((x + w45) * 100 / (2 * w45 + dx))
Color_PercentToRGB()
x1 = w45
y1 = Math.Floor(x / tan)
x2 = 0
y2 = y1 + dy
GW_DrawLine()
EndFor
dy = h45 - Math.Floor(w45 / tan)
For x = 0 To w45
percent = Math.Floor((x + w45 + dx) * 100 / (2 * w45 + dx))
Color_PercentToRGB()
x1 = x
y1 = h45
x2 = w45
y2 = dy + Math.Floor(x / tan)
GW_DrawLine()
EndFor
EndIf
EndIf
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
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 Math_Hex2Dec
' Math | Convert hexadecimal to decimal
' param sHex
' returns iDec
iDec = 0
iLen = Text.GetLength(sHex)
For iPtr = 1 To iLen
iDec = iDec * 16 + Text.GetIndexOf("0123456789ABCDEF", Text.GetSubText(sHex, iPtr, 1)) - 1
EndFor
EndSub

Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param x, y - original coordinate
' param alpha - angle [radian]
' returns x, y - workaround coordinate
If shape[i]["func"] = "tri" Then
x1 = -Math.Floor(shape[i]["x3"] / 2)
y1 = -Math.Floor(shape[i]["y3"] / 2)
ElseIf shape[i]["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shape[i]["x1"] - shape[i]["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shape[i]["y1"] - shape[i]["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 / SBD
' return silverlight - "True" if in remote
' return sbd - "True" if Small Basic Desktop
color = "#000000"
sbd = "False"
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
_gw = GraphicsWindow.Width
_gh = GraphicsWindow.Height
If (_gw = 624) And (_gh = 441) Then
sbd = "True"
EndIf
EndIf
EndSub

Sub SBO_SplitParam
' Small Basic Online | split "index=value;" format as an array param
' param param[] - to split
' return param[] - split
_param = ""
p = 1
len = Text.GetLength(param)
While p <= len
eq = Text.GetIndexOf(Text.GetSubTextToEnd(param, p), "=")
sc = Text.GetIndexOf(Text.GetSubTextToEnd(param, p), ";")
name = Text.GetSubText(param, p, eq - 1)
value = Text.GetSubText(param, p + eq, sc - eq - 1)
_param[name] = value
p = p + sc
EndWhile
param = _param
EndSub

Sub SBO_SplitShape
' Small Basic Online | split "index=value;" format as a jagged array shape
' param shape[] - to split
' return shape[] - split
arry = shape
n = Array.GetItemCount(arry)
For i = 1 To n
param = arry[i]
SBO_SplitParam()
arry[i] = param
EndFor
shape = arry
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 shape[] - shape array
' return shWidth, shHeight - total size of shapes
For i = 1 To Array.GetItemCount(shape)
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_Init_Cake
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 210 ' x offset
shY = 140 ' y offset
shape = ""
shape[1] = "func=ell;x=0;y=180;width=200;height=50;bc=#D6D6D6;pw=0;"
shape[2] = "func=rect;x=0;y=155;width=200;height=51;bc=#D6D6D6;pw=0;"
shape[3] = "func=ell;x=0;y=128;width=200;height=50;bc=#FFFFFF;pw=0;"
shape[4] = "func=ell;x=25;y=139;width=154;height=28;bc=#D6D6D6;pw=0;"
shape[5] = "func=rect;x=25;y=106;width=154;height=48;bc=#D6D6D6;pw=0;"
shape[6] = "func=ell;x=25;y=94;width=154;height=28;bc=#FFFFFF;pw=0;"
shape[7] = "func=ell;x=49;y=101;width=105;height=14;bc=#D6D6D6;pw=0;"
shape[8] = "func=rect;x=49;y=63;width=105;height=45;bc=#D6D6D6;pw=0;"
shape[9] = "func=ell;x=49;y=57;width=105;height=14;bc=#FFFFFF;pw=0;"
shape[10] = "func=ell;x=94;y=61;width=14;height=5;bc=#ED933A;pw=0;"
shape[11] = "func=rect;x=96;y=8;width=10;height=55;bc=#ED933A;pw=0;"
shape[12] = "func=tri;x=96;y=0;x1=5;y1=0;x2=0;y2=10;x3=10;y3=10;bc=#ED933A;pw=0;"
shape[13] = "func=tri;x=71;y=2;x1=5;y1=0;x2=0;y2=10;x3=10;y3=10;bc=#8BED3A;pw=0;"
shape[14] = "func=tri;x=121;y=1;x1=5;y1=0;x2=0;y2=10;x3=10;y3=10;bc=#3AB7ED;pw=0;"
shape[15] = "func=rect;x=121;y=8;width=10;height=55;bc=#3AB7ED;pw=0;"
shape[16] = "func=rect;x=71;y=10;width=10;height=55;bc=#8BED3A;pw=0;"
shape[17] = "func=ell;x=119;y=61;width=14;height=5;bc=#3AB7ED;pw=0;"
shape[18] = "func=ell;x=69;y=61;width=14;height=5;bc=#8BED3A;pw=0;"
shape[19] = "func=ell;x=35;y=99;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[20] = "func=ell;x=53;y=103;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[21] = "func=ell;x=71;y=105;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[22] = "func=ell;x=90;y=106;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[23] = "func=ell;x=109;y=106;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[24] = "func=ell;x=130;y=104;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[25] = "func=ell;x=152;y=99;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[26] = "func=ell;x=11;y=141;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[27] = "func=ell;x=24;y=149;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[28] = "func=ell;x=42;y=154;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[29] = "func=ell;x=65;y=158;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[30] = "func=ell;x=87;y=160;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[31] = "func=ell;x=108;y=160;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[32] = "func=ell;x=131;y=159;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[33] = "func=ell;x=149;y=155;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[34] = "func=ell;x=167;y=150;width=13;height=14;bc=#ED3A3A;pw=0;"
shape[35] = "func=ell;x=180;y=140;width=13;height=14;bc=#ED3A3A;pw=0;"
EndSub

Sub Shapes_Init_Logo
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 260 ' x offset
shY = 180 ' y offset
shape = ""
shape[1] = "func=tri;x=30;y=0;width=14;height=1;x1=7;y1=0;x2=0;y2=1;x3=14;y3=1;pw=0;bc=#F4501F;"
shape[2] = "func=tri;x=36;y=0;width=14;height=1;x1=7;y1=0;x2=0;y2=1;x3=14;y3=1;pw=0;bc=#7CB70A;"
shape[3] = "func=rect;x=37;y=0;width=3;height=1;pw=0;bc=#F4501F;"
shape[4] = "func=rect;x=40;y=0;width=3;height=1;pw=0;bc=#7CB70A;"
shape[5] = "func=tri;x=23;y=1;width=14;height=3;x1=7;y1=0;x2=0;y2=3;x3=14;y3=3;pw=0;bc=#F4501F;"
shape[6] = "func=tri;x=43;y=1;width=14;height=3;x1=7;y1=0;x2=0;y2=3;x3=14;y3=3;pw=0;bc=#7CB70A;"
shape[7] = "func=rect;x=30;y=1;width=10;height=3;pw=0;bc=#F4501F;"
shape[8] = "func=rect;x=40;y=1;width=10;height=3;pw=0;bc=#7CB70A;"
shape[9] = "func=tri;x=17;y=4;width=12;height=3;x1=6;y1=0;x2=0;y2=3;x3=12;y3=3;pw=0;bc=#F4501F;"
shape[10] = "func=tri;x=51;y=4;width=12;height=3;x1=6;y1=0;x2=0;y2=3;x3=12;y3=3;pw=0;bc=#7CB70A;"
shape[11] = "func=rect;x=23;y=4;width=17;height=3;pw=0;bc=#F4501F;"
shape[12] = "func=rect;x=40;y=4;width=17;height=3;pw=0;bc=#7CB70A;"
shape[13] = "func=tri;x=12;y=7;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;pw=0;bc=#F4501F;"
shape[14] = "func=tri;x=58;y=7;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;pw=0;bc=#7CB70A;"
shape[15] = "func=rect;x=17;y=7;width=23;height=5;pw=0;bc=#F4501F;"
shape[16] = "func=rect;x=40;y=7;width=23;height=5;pw=0;bc=#7CB70A;"
shape[17] = "func=tri;x=7;y=12;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;pw=0;bc=#F4501F;"
shape[18] = "func=tri;x=63;y=12;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;pw=0;bc=#7CB70A;"
shape[19] = "func=rect;x=12;y=12;width=28;height=5;pw=0;bc=#F4501F;"
shape[20] = "func=rect;x=40;y=12;width=28;height=5;pw=0;bc=#7CB70A;"
shape[21] = "func=tri;x=4;y=17;width=6;height=6;x1=3;y1=0;x2=0;y2=6;x3=6;y3=6;pw=0;bc=#F4501F;"
shape[22] = "func=tri;x=70;y=17;width=6;height=6;x1=3;y1=0;x2=0;y2=6;x3=6;y3=6;pw=0;bc=#7CB70A;"
shape[23] = "func=rect;x=7;y=17;width=33;height=6;pw=0;bc=#F4501F;"
shape[24] = "func=rect;x=40;y=17;width=33;height=6;pw=0;bc=#7CB70A;"
shape[25] = "func=tri;x=1;y=23;width=6;height=7;x1=3;y1=0;x2=0;y2=7;x3=6;y3=7;pw=0;bc=#F4501F;"
shape[26] = "func=tri;x=73;y=23;width=6;height=7;x1=3;y1=0;x2=0;y2=7;x3=6;y3=7;pw=0;bc=#7CB70A;"
shape[27] = "func=rect;x=4;y=23;width=36;height=7;pw=0;bc=#F4501F;"
shape[28] = "func=rect;x=40;y=23;width=36;height=7;pw=0;bc=#7CB70A;"
shape[29] = "func=tri;x=0;y=30;width=2;height=7;x1=1;y1=0;x2=0;y2=7;x3=2;y3=7;pw=0;bc=#F4501F;"
shape[30] = "func=tri;x=78;y=30;width=2;height=7;x1=1;y1=0;x2=0;y2=7;x3=2;y3=7;pw=0;bc=#7CB70A;"
shape[31] = "func=rect;x=1;y=30;width=39;height=7;pw=0;bc=#F4501F;"
shape[32] = "func=rect;x=40;y=30;width=39;height=7;pw=0;bc=#7CB70A;"
shape[33] = "func=rect;x=0;y=37;width=40;height=3;pw=0;bc=#F4501F;"
shape[34] = "func=rect;x=40;y=37;width=40;height=3;pw=0;bc=#7CB70A;"
shape[35] = "func=rect;x=0;y=40;width=40;height=3;angle=180;pw=0;bc=#03A3ED;"
shape[36] = "func=rect;x=40;y=40;width=40;height=3;angle=180;pw=0;bc=#FCB901;"
shape[37] = "func=tri;x=0;y=43;width=2;height=7;x1=1;y1=0;x2=0;y2=7;x3=2;y3=7;angle=180;pw=0;bc=#03A3ED;"
shape[38] = "func=tri;x=78;y=43;width=2;height=7;x1=1;y1=0;x2=0;y2=7;x3=2;y3=7;angle=180;pw=0;bc=#FCB901;"
shape[39] = "func=rect;x=1;y=43;width=39;height=7;angle=180;pw=0;bc=#03A3ED;"
shape[40] = "func=rect;x=40;y=43;width=39;height=7;angle=180;pw=0;bc=#FCB901;"
shape[41] = "func=tri;x=1;y=50;width=6;height=7;x1=3;y1=0;x2=0;y2=7;x3=6;y3=7;angle=180;pw=0;bc=#03A3ED;"
shape[42] = "func=tri;x=73;y=50;width=6;height=7;x1=3;y1=0;x2=0;y2=7;x3=6;y3=7;angle=180;pw=0;bc=#FCB901;"
shape[43] = "func=rect;x=4;y=50;width=36;height=7;angle=180;pw=0;bc=#03A3ED;"
shape[44] = "func=rect;x=40;y=50;width=36;height=7;angle=180;pw=0;bc=#FCB901;"
shape[45] = "func=tri;x=4;y=57;width=6;height=6;x1=3;y1=0;x2=0;y2=6;x3=6;y3=6;angle=180;pw=0;bc=#03A3ED;"
shape[46] = "func=tri;x=70;y=57;width=6;height=6;x1=3;y1=0;x2=0;y2=6;x3=6;y3=6;angle=180;pw=0;bc=#FCB901;"
shape[47] = "func=rect;x=7;y=57;width=33;height=6;angle=180;pw=0;bc=#03A3ED;"
shape[48] = "func=rect;x=40;y=57;width=33;height=6;angle=180;pw=0;bc=#FCB901;"
shape[49] = "func=tri;x=7;y=63;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;angle=180;pw=0;bc=#03A3ED;"
shape[50] = "func=tri;x=63;y=63;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;angle=180;pw=0;bc=#FCB901;"
shape[51] = "func=rect;x=12;y=63;width=28;height=5;angle=180;pw=0;bc=#03A3ED;"
shape[52] = "func=rect;x=40;y=63;width=28;height=5;angle=180;pw=0;bc=#FCB901;"
shape[53] = "func=tri;x=12;y=68;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;angle=180;pw=0;bc=#03A3ED;"
shape[54] = "func=tri;x=58;y=68;width=10;height=5;x1=5;y1=0;x2=0;y2=5;x3=10;y3=5;angle=180;pw=0;bc=#FCB901;"
shape[55] = "func=rect;x=17;y=68;width=23;height=5;angle=180;pw=0;bc=#03A3ED;"
shape[56] = "func=rect;x=40;y=68;width=23;height=5;angle=180;pw=0;bc=#FCB901;"
shape[57] = "func=tri;x=17;y=73;width=12;height=3;x1=6;y1=0;x2=0;y2=3;x3=12;y3=3;angle=180;pw=0;bc=#03A3ED;"
shape[58] = "func=tri;x=51;y=73;width=12;height=3;x1=6;y1=0;x2=0;y2=3;x3=12;y3=3;angle=180;pw=0;bc=#FCB901;"
shape[59] = "func=rect;x=23;y=73;width=17;height=3;angle=180;pw=0;bc=#03A3ED;"
shape[60] = "func=rect;x=40;y=73;width=17;height=3;angle=180;pw=0;bc=#FCB901;"
shape[61] = "func=tri;x=23;y=76;width=14;height=3;x1=7;y1=0;x2=0;y2=3;x3=14;y3=3;angle=180;pw=0;bc=#03A3ED;"
shape[62] = "func=tri;x=43;y=76;width=14;height=3;x1=7;y1=0;x2=0;y2=3;x3=14;y3=3;angle=180;pw=0;bc=#FCB901;"
shape[63] = "func=rect;x=30;y=76;width=10;height=3;angle=180;pw=0;bc=#03A3ED;"
shape[64] = "func=rect;x=40;y=76;width=10;height=3;angle=180;pw=0;bc=#FCB901;"
shape[65] = "func=tri;x=30;y=79;width=14;height=1;x1=7;y1=0;x2=0;y2=1;x3=14;y3=1;angle=180;pw=0;bc=#03A3ED;"
shape[66] = "func=tri;x=36;y=79;width=14;height=1;x1=7;y1=0;x2=0;y2=1;x3=14;y3=1;angle=180;pw=0;bc=#FCB901;"
shape[67] = "func=rect;x=37;y=79;width=3;height=1;angle=180;pw=0;bc=#03A3ED;"
shape[68] = "func=rect;x=40;y=79;width=3;height=1;angle=180;pw=0;bc=#FCB901;"
shape[69] = "func=tri;x=22;y=14;width=36;height=8;x1=18;y1=0;x2=0;y2=8;x3=36;y3=8;pw=0;bc=White;"
shape[70] = "func=tri;x=14;y=22;width=16;height=18;x1=8;y1=0;x2=0;y2=18;x3=16;y3=18;pw=0;bc=White;"
shape[71] = "func=tri;x=50;y=22;width=16;height=18;x1=8;y1=0;x2=0;y2=18;x3=16;y3=18;pw=0;bc=White;"
shape[72] = "func=rect;x=22;y=22;width=36;height=18;pw=0;bc=White;"
shape[73] = "func=tri;x=14;y=40;width=16;height=18;x1=8;y1=0;x2=0;y2=18;x3=16;y3=18;angle=180;pw=0;bc=White;"
shape[74] = "func=tri;x=50;y=40;width=16;height=18;x1=8;y1=0;x2=0;y2=18;x3=16;y3=18;angle=180;pw=0;bc=White;"
shape[75] = "func=rect;x=22;y=40;width=36;height=18;angle=180;pw=0;bc=White;"
shape[76] = "func=tri;x=22;y=58;width=36;height=8;x1=18;y1=0;x2=0;y2=8;x3=36;y3=8;angle=180;pw=0;bc=White;"
shape[77] = "func=tri;x=24;y=18;width=32;height=6;x1=16;y1=0;x2=0;y2=6;x3=32;y3=6;pw=0;bc=DimGray;"
shape[78] = "func=tri;x=18;y=24;width=12;height=16;x1=6;y1=0;x2=0;y2=16;x3=12;y3=16;pw=0;bc=DimGray;"
shape[79] = "func=tri;x=50;y=24;width=12;height=16;x1=6;y1=0;x2=0;y2=16;x3=12;y3=16;pw=0;bc=DimGray;"
shape[80] = "func=rect;x=24;y=24;width=32;height=16;pw=0;bc=DimGray;"
shape[81] = "func=tri;x=18;y=40;width=12;height=16;x1=6;y1=0;x2=0;y2=16;x3=12;y3=16;angle=180;pw=0;bc=DimGray;"
shape[82] = "func=tri;x=50;y=40;width=12;height=16;x1=6;y1=0;x2=0;y2=16;x3=12;y3=16;angle=180;pw=0;bc=DimGray;"
shape[83] = "func=rect;x=24;y=40;width=32;height=16;angle=180;pw=0;bc=DimGray;"
shape[84] = "func=tri;x=24;y=56;width=32;height=6;x1=16;y1=0;x2=0;y2=6;x3=32;y3=6;angle=180;pw=0;bc=DimGray;"
shape[85] = "func=tri;x=28;y=23;width=24;height=5;x1=12;y1=0;x2=0;y2=5;x3=24;y3=5;pw=0;bc=White;"
shape[86] = "func=tri;x=23;y=28;width=10;height=12;x1=5;y1=0;x2=0;y2=12;x3=10;y3=12;pw=0;bc=White;"
shape[87] = "func=tri;x=47;y=28;width=10;height=12;x1=5;y1=0;x2=0;y2=12;x3=10;y3=12;pw=0;bc=White;"
shape[88] = "func=rect;x=28;y=28;width=24;height=12;pw=0;bc=White;"
shape[89] = "func=tri;x=23;y=40;width=10;height=12;x1=5;y1=0;x2=0;y2=12;x3=10;y3=12;angle=180;pw=0;bc=White;"
shape[90] = "func=tri;x=47;y=40;width=10;height=12;x1=5;y1=0;x2=0;y2=12;x3=10;y3=12;angle=180;pw=0;bc=White;"
shape[91] = "func=rect;x=28;y=40;width=24;height=12;angle=180;pw=0;bc=White;"
shape[92] = "func=tri;x=28;y=52;width=24;height=5;x1=12;y1=0;x2=0;y2=5;x3=24;y3=5;angle=180;pw=0;bc=White;"
shape[93] = "func=line;x=0;y=40;width=16;height=0;x1=0;y1=0;x2=16;y2=0;pw=3.2;pc=White;"
shape[94] = "func=line;x=11.71;y=11.71;width=11.31;height=11.31;x1=0.00;y1=0.00;x2=11.31;y2=11.31;pw=3.2;pc=White;"
shape[95] = "func=line;x=40;y=0;width=0;height=16;x1=0;y1=0;x2=0;y2=16;pw=3.2;pc=White;"
shape[96] = "func=line;x=56.97;y=11.71;width=11.31;height=11.31;x1=11.31;y1=0.00;x2=0.00;y2=11.31;pw=3.2;pc=White;"
shape[97] = "func=line;x=64;y=39.99;width=16;height=0.00;x1=16;y1=0.00;x2=0;y2=0.00;pw=3.2;pc=White;"
shape[98] = "func=line;x=56.97;y=56.97;width=11.31;height=11.31;x1=11.31;y1=11.31;x2=0.00;y2=0.00;pw=3.2;pc=White;"
shape[99] = "func=line;x=40;y=64;width=0;height=16;x1=0;y1=16;x2=0;y2=0;pw=3.2;pc=White;"
shape[100] = "func=line;x=11.71;y=56.97;width=11.31;height=11.31;x1=0.00;y1=11.31;x2=11.31;y2=0.00;pw=3.2;pc=White;"
shape[101] = "func=line;x=0;y=40;width=16;height=0;x1=0;y1=0;x2=16;y2=0;pw=3.2;pc=White;"
shape[102] = "func=line;x=23.2;y=40;width=33.6;height=0;x1=0.0;y1=0;x2=33.6;y2=0;pw=5.6;pc=DimGray;"
shape[103] = "func=line;x=40;y=23.2;width=0;height=33.6;x1=0;y1=0.0;x2=0;y2=33.6;pw=14.4;pc=DimGray;"
shape[104] = "func=line;x=40;y=14.4;width=0;height=51.2;x1=0;y1=0.0;x2=0;y2=51.2;pw=3.2;pc=White;"
shape[105] = "func=line;x=31.2;y=35.6;width=8.8;height=0.0;x1=0.0;y1=0.0;x2=8.8;y2=0.0;pw=3.2;pc=White;"
shape[106] = "func=line;x=17.6;y=44.4;width=8.8;height=0.0;x1=0.0;y1=0.0;x2=8.8;y2=0.0;pw=3.2;pc=White;"
EndSub

Sub Sprite_Add
' Sprite | add shapes to a sprite
' param name - sprite name
' param shX, shY - origin of shape array
' param scale - to resize
' param shape[] - shape array
' param nSprite - number of sprite
' return nSprite - updated number of sprite
' return sprite[] - sprite array
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
nSprite = nSprite + 1
spr = ""
spr["name"] = name
spr["x"] = shX
spr["y"] = shY
spr["angle"] = 0
spr["dir"] = 1
Shapes_CalcWidthAndHeight()
spr["width"] = shWidth
spr["height"] = shHeight
spr["cx"] = shWidth / 2
spr["cy"] = shHeight / 2
If scale = "" Then
scale = 1
EndIf
s = scale
spr["scale"] = s
For i = 1 To Array.GetItemCount(shape)
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|btn", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If Text.IsSubText("text|btn", shp["func"]) Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
If shp["fb"] = "False" Then
GraphicsWindow.FontBold = "False"
Else
GraphicsWindow.FontBold = "True"
EndIf
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
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If sbd And (shp["func"] = "line") Then
shp["wx"] = x
shp["wy"] = y
ElseIf silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
If shp["func"] = "btn" Then
shp["obj"] = Controls.AddButton(shp["caption"], shX + x * s, shY + y * s)
Else
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
EndIf
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
spr["shape"] = shape
sprite[nSprite] = spr
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub

Sub Sprite_Move
' Sprite | move a sprite
' param sprite[i] - sprite to move
' param x, y - position to move
' return sprite[i] - updated sprite
Stack.PushValue("local", j)
spr = sprite[i]
s = spr["scale"]
spr["x"] = x
spr["y"] = y
shape = spr["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
If sbd And (shp["func"] = "line") Then
_x = shp["wx"]
_y = shp["wy"]
ElseIf 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"], spr["x"] + _x * s, spr["y"] + _y * s)
EndFor
sprite[i] = spr
j = Stack.PopValue("local")
EndSub