Microsoft Small Basic

Program Listing: XKB601
' Happy Star Wars Year 2015
' Shapes generated by GetShapes PowerPoint VBA Version 0.3
' Copyright © 2015 Nonki Takahashi. The MIT License.
' Last update 2015-11-02
'
GraphicsWindow.Title = "Happy Star Wars Year 2015"
WQ = Text.GetCharacter(34)
bg = "#000033"
GraphicsWindow.BackgroundColor = bg
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
DrawStars()
' initialize shapes
Shapes_Init()
' add shapes
scale = 1
angle = 0
iMin = 1
iMax = 61
Shapes_Add()
Sub DrawStars
color = "White"
For i = 1 To 1000
x = Math.GetRandomNumber(gw)
y = Math.GetRandomNumber(gh)
GraphicsWindow.SetPixel(x, y, color)
EndFor
EndSub
Sub Shapes_Init
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 0 ' x offset
shY = 0 ' y offset
shape = ""
shape[1] = "func=tri;x=229;y=80;x1=69;y1=0;x2=0;y2=172;x3=138;y3=172;pw=0;bc=#000000;name=Isosceles Triangle 72;"
shape[2] = "func=rect;x=213;y=137;width=169;height=89;pw=0;bc=#000000;name=Rectangle 13;"
shape[3] = "func=ell;x=213;y=40;width=107;height=124;pw=0;bc=#000000;name=Oval 3;"
shape[4] = "func=ell;x=275;y=40;width=107;height=124;pw=0;bc=#000000;name=Oval 27;"
shape[5] = "func=ell;x=229;y=85;width=65;height=60;pw=0;bc=#7F7F7F;name=Oval 8;"
shape[6] = "func=ell;x=302;y=85;width=65;height=60;pw=0;bc=#7F7F7F;name=Oval 35;"
shape[7] = "func=ell;x=304;y=113;width=62;height=49;pw=0;bc=#262626;name=Oval 41;"
shape[8] = "func=ell;x=229;y=113;width=62;height=49;pw=0;bc=#262626;name=Oval 14;"
shape[9] = "func=ell;x=228;y=94;width=65;height=51;pw=0;bc=#000000;name=Oval 36;"
shape[10] = "func=ell;x=303;y=93;width=65;height=51;pw=0;bc=#000000;name=Oval 37;"
shape[11] = "func=ell;x=236;y=105;width=51;height=37;pw=0;bc=#780000;name=Oval 11;"
shape[12] = "func=ell;x=308;y=103;width=51;height=37;pw=0;bc=#780000;name=Oval 38;"
shape[13] = "func=tri;x=236;y=121;x1=61;y1=0;x2=0;y2=105;x3=123;y3=105;pw=0;bc=#7F7F7F;name=Isosceles Triangle 12;"
shape[14] = "func=tri;x=170;y=104;x1=42;y1=0;x2=0;y2=130;x3=85;y3=130;pw=0;bc=#000000;name=Isosceles Triangle 5;"
shape[15] = "func=tri;x=341;y=105;x1=42;y1=0;x2=0;y2=130;x3=84;y3=130;pw=0;bc=#000000;name=Isosceles Triangle 39;"
shape[16] = "func=ell;x=243;y=33;width=108;height=29;pw=0;bc=#101010;name=Oval 94;"
shape[17] = "func=rect;x=292;y=29;width=13;height=106;pw=0;bc=#000000;name=Rectangle 10;"
shape[18] = "func=line;x=192;y=106;x1=0;y1=127;x2=39;y2=0;pw=3;pc=#7F7F7F;bc=#000000;name=Straight Connector 49;"
shape[19] = "func=line;x=363;y=103;x1=0;y1=0;x2=36;y2=130;pw=3;pc=#7F7F7F;bc=#000000;name=Straight Connector 51;"
shape[20] = "func=line;x=346;y=173;x1=0;y1=51;x2=11;y2=0;pw=10;pc=#404040;bc=#000000;name=Straight Connector 55;"
shape[21] = "func=ell;x=287;y=123;width=22;height=22;pw=0;bc=#7F7F7F;name=Oval 67;"
shape[22] = "func=ell;x=287;y=136;width=22;height=22;pw=0;bc=#262626;name=Oval 68;"
shape[23] = "func=tri;x=250;y=146;x1=46;y1=0;x2=0;y2=78;x3=93;y3=78;pw=10;pc=#262626;bc=#595959;name=Isosceles Triangle 40;"
shape[24] = "func=tri;x=265;y=157;x1=31;y1=0;x2=0;y2=52;x3=63;y3=52;pw=0;bc=#000000;name=Isosceles Triangle 15;"
shape[25] = "func=line;x=297;y=157;x1=0;y1=68;x2=0;y2=0;pw=10;pc=#262626;bc=#000000;name=Straight Connector 42;"
shape[26] = "func=line;x=317;y=185;x1=0;y1=39;x2=0;y2=0;pw=10;pc=#262626;bc=#000000;name=Straight Connector 45;"
shape[27] = "func=line;x=276;y=185;x1=0;y1=39;x2=0;y2=0;pw=10;pc=#262626;bc=#000000;name=Straight Connector 48;"
shape[28] = "func=line;x=236;y=173;x1=0;y1=0;x2=13;y2=52;pw=10;pc=#404040;bc=#000000;name=Straight Connector 53;"
shape[29] = "func=ell;x=241;y=214;width=17;height=17;pw=0;bc=#262626;name=Oval 60;"
shape[30] = "func=ell;x=335;y=215;width=17;height=17;pw=0;bc=#262626;name=Oval 62;"
shape[31] = "func=rect;x=139;y=249;width=320;height=178;pw=0;bc=#000000;name=Rectangle 73;"
shape[32] = "func=ell;x=414;y=249;width=87;height=85;pw=0;bc=#000000;name=Oval 74;"
shape[33] = "func=ell;x=97;y=249;width=87;height=85;pw=0;bc=#000000;name=Oval 75;"
shape[34] = "func=tri;x=350;y=280;x1=42;y1=0;x2=0;y2=98;x3=84;y3=98;angle=90;pw=0;bc=#595959;name=Isosceles Triangle 76;"
shape[35] = "func=tri;x=160;y=284;x1=42;y1=0;x2=0;y2=94;x3=84;y3=94;angle=270;pw=0;bc=#595959;name=Isosceles Triangle 77;"
shape[36] = "func=rect;x=249;y=275;width=96;height=96;pw=0;bc=#595959;name=Rectangle 78;"
shape[37] = "func=rect;x=155;y=277;width=286;height=52;pw=0;bc=#595959;name=Rectangle 88;"
shape[38] = "func=rect;x=245;y=277;width=34;height=96;pw=0;bc=#262626;name=Rectangle 79;"
shape[39] = "func=rect;x=312;y=274;width=34;height=97;pw=0;bc=#262626;name=Rectangle 80;"
shape[40] = "func=tri;x=191;y=334;x1=10;y1=0;x2=0;y2=25;x3=20;y3=25;angle=270;pw=0;bc=#262626;name=Isosceles Triangle 81;"
shape[41] = "func=tri;x=385;y=332;x1=10;y1=0;x2=0;y2=25;x3=21;y3=25;angle=90;pw=0;bc=#262626;name=Isosceles Triangle 82;"
shape[42] = "func=ell;x=228;y=258;width=136;height=28;pw=0;bc=#000000;name=Oval 83;"
shape[43] = "func=tri;x=42;y=283;x1=56;y1=0;x2=0;y2=144;x3=112;y3=144;pw=0;bc=#000000;name=Isosceles Triangle 84;"
shape[44] = "func=tri;x=444;y=283;x1=56;y1=0;x2=0;y2=144;x3=112;y3=144;pw=0;bc=#000000;name=Isosceles Triangle 85;"
shape[45] = "func=rect;x=192;y=274;width=22;height=70;pw=0;bc=#262626;name=Rectangle 86;"
shape[46] = "func=rect;x=383;y=269;width=25;height=74;pw=0;bc=#262626;name=Rectangle 87;"
shape[47] = "func=ell;x=359;y=259;width=136;height=28;pw=0;bc=#000000;name=Oval 89;"
shape[48] = "func=ell;x=105;y=262;width=136;height=28;pw=0;bc=#000000;name=Oval 90;"
shape[49] = "func=rect;x=227;y=384;width=141;height=78;pw=6;pc=#7F7F7F;bc=#000000;name=Rectangle 91;"
shape[50] = "func=rect;x=391;y=315;width=148;height=50;angle=75.14647;pw=0;bc=#000000;name=Rectangle 92;"
shape[51] = "func=rect;x=58;y=309;width=148;height=50;angle=108.2733;pw=0;bc=#000000;name=Rectangle 93;"
shape[52] = "func=rect;x=249;y=403;width=41;height=16;pw=0;bc=#7F7F7F;name=Rectangle 95;"
shape[53] = "func=rect;x=249;y=429;width=41;height=16;pw=0;bc=#7F7F7F;name=Rectangle 96;"
shape[54] = "func=rect;x=328;y=403;width=17;height=16;pw=0;bc=#7F7F7F;name=Rectangle 97;"
shape[55] = "func=rect;x=328;y=428;width=17;height=16;pw=0;bc=#7F7F7F;name=Rectangle 98;"
shape[56] = "func=rect;x=261;y=408;width=18;height=8;pw=0;bc=#FF0000;name=Rectangle 99;"
shape[57] = "func=rect;x=261;y=435;width=18;height=8;pw=0;bc=#FF0000;name=Rectangle 100;"
shape[58] = "func=rect;x=330;y=430;width=11;height=12;pw=0;bc=#FF0000;name=Rectangle 101;"
shape[59] = "func=tri;x=265;y=237;x1=31;y1=0;x2=0;y2=19;x3=63;y3=19;angle=180;pw=0;bc=#262626;name=Isosceles Triangle 102;"
shape[60] = "func=rect;x=91;y=-12;width=18;height=448;angle=350.1851;pw=0;bc=#FF0000;name=Rectangle 111;"
shape[61] = "func=text;text=I AM YOUR FATHER;fn=Trebuchet MS;fs=60;fb=False;fi=False;x=45;y=295;width=508;height=79;pw=0;bc=#FFFFFF;name=TextBox 109;"
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|line|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_Convert
' Shapes | Convert virtual function to function
' return iMax
For i = iMin To iMax
shp = shape[i]
If shp["func"] = "hex" Then
If shp["name"] = "" Then
shp["name"] = "Hexagon"
EndIf
For j = iMax To i + 1 Step -1
shape[j + 8] = shape[j]
EndFor
_x[1] = shp["x"] + shp["height"] * shp["ratio"]
_y[1] = shp["y"]
_x[2] = shp["x"] + shp["width"] - shp["height"] * shp["ratio"]
_y[2] = shp["y"]
_x[3] = shp["x"] + shp["width"]
_y[3] = shp["y"] + shp["height"] / 2
_x[4] = shp["x"] + shp["width"] - shp["height"] * shp["ratio"]
_y[4] = shp["y"] + shp["height"]
_x[5] = shp["x"] + shp["height"] * shp["ratio"]
_y[5] = shp["y"] + shp["height"]
_x[6] = shp["x"]
_y[6] = shp["y"] + shp["height"] / 2
For j = 1 To 6
_x[j] = Math.Floor(_x[j] * 100) / 100
_y[j] = Math.Floor(_y[j] * 100) / 100
EndFor
_width = _y[5] - _y[1]
_height = _x[1] - _x[6]
x = (_x[1] + _x[6]) / 2 - _width / 2
y = (_y[1] + _y[5]) / 2 - _height / 2
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 270
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";pw=0;bc="+shp["bc"]+";angle="+angle+";name="+shp["name"]+";"
_width = _x[2] - _x[1]
_height = _y[5] - _y[1]
x = _x[1]
y = _y[1]
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 1] = "func=rect;x="+x+";y="+y+";width="+_width+";height="+_height+";pw=0;bc="+shp["bc"]+";angle="+angle+";name="+shp["name"]+";"
_width = _y[5] - _y[1]
_height = _x[1] - _x[6]
x = (_x[2] + _x[3]) / 2 - _width / 2
y = (_y[2] + _y[4]) / 2 - _height / 2
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 90
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 2] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";pw=0;bc="+shp["bc"]+";angle="+angle+";name="+shp["name"]+";"
x = _x[1]
y = _y[1] + shp["pw"] / 2
_width = _x[2] - _x[1]
_height = 0
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 3] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[3] - _x[2]
_height = _y[3] - _y[2]
_a = Math.ArcTan(_width/_height)
x = _x[2] - shp["pw"] / 2 * Math.Cos(_a)
y = _y[2] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 4] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[3] - _x[4]
_height = _y[4] - _y[3]
_a = Math.ArcTan(_width/_height)
x = _x[4] - shp["pw"] / 2 * Math.Cos(_a)
y = _y[3] - shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = _height
_x2 = _width
_y2 = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 5] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
x = _x[5]
y = _y[5] - shp["pw"] / 2
_width = _x[4] - _x[5]
_height = 0
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 6] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[5] - _x[6]
_height = _y[5] - _y[6]
_a = Math.ArcTan(_width/_height)
x = _x[6] + shp["pw"] / 2 * Math.Cos(_a)
y = _y[6] - shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 7] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[1] - _x[6]
_height = _y[6] - _y[1]
_a = Math.ArcTan(_width/_height)
x = _x[6] + shp["pw"] / 2 * Math.Cos(_a)
y = _y[1] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = _height
_x2 = _width
_y2 = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 8] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
iMax = iMax + 8
ElseIf shp["func"] = "trap" Then
If shp["name"] = "" Then
shp["name"] = "Trapezoid"
EndIf
For j = iMax To i + 1 Step -1
shape[j + 6] = shape[j]
EndFor
_x[1] = shp["x"] + shp["height"] * shp["ratio"]
_y[1] = shp["y"]
_x[2] = shp["x"] + shp["width"] - shp["height"] * shp["ratio"]
_y[2] = shp["y"]
_x[3] = shp["x"] + shp["width"]
_y[3] = shp["y"] + shp["height"]
_x[4] = shp["x"]
_y[4] = shp["y"] + shp["height"]
_width = (_x[1] - _x[4]) * 2
_height = _y[4] - _y[1]
x = _x[4]
y = _y[1]
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";angle="+angle+";pw=0;bc="+shp["bc"]+";name="+shp["name"]+";"
_width = _x[2] - _x[1]
_height = _y[4] - _y[1]
x = _x[1]
y = _y[1]
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 1] = "func=rect;x="+x+";y="+y+";width="+_width+";height="+_height+";angle="+angle+";pw=0;bc="+shp["bc"]+";name="+shp["name"]+";"
_width = (_x[3] - _x[2]) * 2
_height = _y[3] - _y[2]
x = _x[2] - _width / 2
y = _y[2]
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 2] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";angle="+angle+";pw=0;bc="+shp["bc"]+";name="+shp["name"]+";"
_width = _x[2] - _x[1]
_height = _y[2] - _y[1]
x = _x[1]
y = _y[1] + shp["pw"] / 2
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 3] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[3] - _x[2]
_height = _y[3] - _y[2]
_a = Math.ArcTan(_width/_height)
x = _x[2] - shp["pw"] / 2 * Math.Cos(_a)
y = _y[2] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 4] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
x = _x[4]
y = _y[4] - shp["pw"] / 2
_width = _x[3] - _x[4]
_height = 0
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 5] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[1] - _x[4]
_height = _y[4] - _y[1]
_a = Math.ArcTan(_width/_height)
x = _x[4] + shp["pw"] / 2 * Math.Cos(_a)
y = _y[1] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = _height
_x2 = _width
_y2 = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 6] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
iMax = iMax + 6
EndIf
EndFor
EndSub
Sub Shapes_CalcRotateFill
' Shapes | Calculate position for rotated fill shape
' param x, y - shape position
' param angle - shape angle
' param shp["angle"] - rotate angle
' param shp["x"], shp["y"] - for rotate center
' param shp["width"], shp["height"] - for rotate center
' return x, y - rotated shape position
' return angle - rotated shape angle
param["x"] = x
param["y"] = y
param["width"] = _width
param["height"] = _height
param["cx"] = shp["x"] + shp["width"] / 2
param["cy"] = shp["y"] + shp["height"] / 2
param["angle"] = shp["angle"]
Shapes_CalcRotatePos()
angle = Math.Remainder(angle + shp["angle"], 360)
EndSub
Sub Shapes_CalcRotateLine
' Shapes | Calculate position for rotated line
' param["x"], param["y"] - line position
' param["angle"] - rotate angle
' param _x1, _y1, _x2, _y2 - relative position of the first and second point of the line
' return x, y - rotated line position
' return _x1, _y1, _x2, _y2 - rotated position of the line
cx = shp["x"] + shp["width"] / 2
cy = shp["y"] + shp["height"] / 2
_a = Math.GetRadians(shp["angle"])
_rx1 = (_x1 + x - cx) * Math.Cos(_a) + (_y1 + y - cy) * Math.Sin(_a) + cx
_ry1 = -(_x1 + x - cx) * Math.Sin(_a) + (_y1 + y - cy) * Math.Cos(_a) + cy
_rx2 = (_x2 + x - cx) * Math.Cos(_a) + (_y2 + y - cy) * Math.Sin(_a) + cx
_ry2 = -(_x2 + x - cx) * Math.Sin(_a) + (_y2 + y - cy) * Math.Cos(_a) + cy
x = Math.Min(_rx1, _rx2)
y = Math.Min(_ry1, _ry2)
_x1 = _rx1 - x
_x2 = _rx2 - x
_y1 = _ry1 - y
_y2 = _ry2 - y
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_Dump
' Shapes | Dump shape array for debug
For i = iMin To iMax
TextWindow.WriteLine("shape[" + i + "]=" + WQ + shape[i] + WQ)
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
' param forConv - "True" if for conversion
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