Skip to content

Instantly share code, notes, and snippets.

@nonkitMac
Forked from nonkit/Shapes_CalcRotateZoomPos.sb
Last active December 16, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonkitMac/cb3125cf320342bdfe7bb71fabd81f67 to your computer and use it in GitHub Desktop.
Save nonkitMac/cb3125cf320342bdfe7bb71fabd81f67 to your computer and use it in GitHub Desktop.
Small Basic Shapes Subroutines
Sub Shapes_CalcRotateZoomPos
' Shapes | calculate position for rotated and zoomed 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
' param ["scale"] - resize scale
' 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) * param["scale"]
y = (_cy - param["height"] / 2) * param["scale"]
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
' Shapes | initialize sample shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 100 ' x offset
shY = 100 ' 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment