Microsoft Small Basic

Program Listing: SLG752-3
'Challenge of the Month - November 2017 -- Animation Challenge -- by NaochanON
'WXB487 --> SLG752-1 --> SLG752-3 moving around using legs
GraphicsWindow.Left=10
GraphicsWindow.top=10
GraphicsWindow.width=1000
GraphicsWindow.height=650
GraphicsWindow.BackgroundColor="#BADCAD"
data()
addshapes()
partsposition() ' all position
dir="-1:1=Left-Up;1:1=Right-Up;-1:-1=Left-Down;1:-1=Right-Down"
rot="-1:1=0;1:1=0;-1:-1=3.14;1:-1=3.14"
NN=3
PM=1

While "True"
NN=NN+1
dY=dY+(3-Math.GetRandomNumber(3))
dX=dX+(5-Math.GetRandomNumber(8))
If C_Y<0 or C_Y>600 Then
dY=dY-5*C_Y/Math.Abs(C_Y)
dY=-dY
EndIf
If C_X<0 or C_X>1000 Then
dX=dX-5
dX=-dX
EndIf
_dir=math.Floor(dx/Math.Abs(dX))+":"+Math.Floor(dY/Math.Abs(dY))'4 patterns -1:-1 , -1:1 ,1:-1 ,1:1
dS=-math.ArcTan(dx/(dy+0.000000000001))+rot[_dir] '
deg=Math.GetDegrees(dS)
GraphicsWindow.Title="Moving direcion.... "+dir[_dir]+ " : angle= "+math.floor(-deg)
ddx=-dX/(NN+3)
ddy=dY/(NN+3)
shapes_move()
k=K+PM
LRLegs_moving()
Program.Delay(50)
If NN>10 Then
NN=3
EndIf
If k>4 Or K<1 Then
PM=-PM
EndIf
EndWhile

Sub LRLegs_moving
name="1=L1;2=L2;3=L3;4=R1;5=R2;6=R3;7=L;8=R"
stNMB="1=0;2=5;3=9;4=13;5=18;6=22;7=37;8=40"
MaxNMB="1=5;2=4;3=4;4=5;5=4;6=4;7=3;8=3"
For L=1 To 8
For j=1 To maxnmb[L]
newdeg[L][j]=L_ang["1"+name[L] ][j] +(L_ang["2"+name[L] ][j] - L_ang["1"+name[L] ][j])/5*k - deg '<----------
EndFor
_xL=Shapes.GetLeft(shp[stnmb[L]+1])+shape[stnmb[L]+1]["wd"]/2*s -shape[stnmb[L]+1]["ht"]/2*Math.Sin(Math.GetRadians(newdeg[L][1]))*s 'left anker
_yL=Shapes.Gettop(shp[stnmb[L]+1]) +shape[stnmb[L]+1]["ht"]/2*s +shape[stnmb[L]+1]["ht"]/2*Math.cos(Math.GetRadians(newdeg[L][1]))*s '
For j=1 To maxnmb[L]
_cx=_xL+shape[stnmb[L]+j]["ht"]/2*Math.Sin(Math.GetRadians(newdeg[L][j]))*s
_cy=_yL-shape[stnmb[L]+j]["ht"]/2*Math.cos(Math.GetRadians(newdeg[L][j]))*s
Shapes.Move(shp[stnmb[L]+j],_cx -shape[stnmb[L]+j]["wd"]/2*s,_cy-shape[stnmb[L]+j]["ht"]/2*s)
Shapes.Rotate(shp[stnmb[L]+j],newdeg[L][j])
_xL=_cx+shape[stnmb[L]+j]["ht"]/2*Math.Sin(Math.GetRadians(newdeg[L][j]))*s'new left anker
_yL=_cy-shape[stnmb[L]+j]["ht"]/2*Math.cos(Math.GetRadians(newdeg[L][j]))*s
EndFor
EndFor
EndSub

Sub shapes_move
Shapes.Move(ell[0], Shapes.GetLeft(ell[0])-ddx,Shapes.Gettop(ell[0])-ddy)
C_X=shapes.GetLeft( ell[0])+2
C_Y=shapes.Gettop( ell[0])+2
snmb="02:03:04:05:07:08:09:11:12:13:15:16:17:18:20:21:22:24:25:26:39:40:42:43:"
For i=1 to Array.GetItemCount(shape)
If Text.IsSubText(snmb,text.GetSubTextToEnd(100+i,2))="False" Then
Shapes.Move(ell[i],C_X+DR[i]*Math.Sin(rad[i]+dS)-2,C_Y+DR[i]*Math.cos(rad[i]+dS)-2)
elx=shapes.GetLeft(ell[i])
ely=shapes.Gettop(ell[i])
Shapes.Move(shp[i],elx +2 - shape[i]["wd"]/2*s,ely+2 - shape[i]["ht"]/2*s)
Shapes.Rotate(shp[i],-deg+shape[i]["ag"])
EndIf
EndFor
EndSub

Sub partsposition
For j=1 To Array.GetItemCount(shape)
If Text.IsSubText("rect:ell:", shape[J]["fn"]) Then
dx=C_X-(Shapes.GetLeft(shp[j])+shape[j]["wd"]/2*s)
dy=C_Y-(Shapes.Gettop(shp[j])+shape[j]["ht"]/2*s)
ElseIf shape[J]["fn"]="tri" Then
dx=C_X-( Shapes.GetLeft(shp[j])+ (shape[j]["x1"]+shape[j]["x2"])/2*s )
dy=C_Y-( Shapes.Gettop(shp[j]) + (shape[j]["y1"]+shape[j]["y3"])/2*s )
EndIf
ell[j]=Shapes.AddEllipse(4,4)
Shapes.Move(ell[j], C_X-2-dx,C_Y-2-dy)
Shapes.SetOpacity(ell[j],0)
DR[j]=Math.SquareRoot(dx*dx+dy*dy) ' length
rad[j]=math.ArcTan(dx/(dy+0.000000000001))-Math.pi' angle
EndFor
EndSub

Sub addshapes
s=0.65
shx=300
shy=300
C_X= shx + shape[27]["x"]*s + shape[27]["wd"]/2*s
C_Y= shy + shape[27]["y"]*s + shape[27]["ht"]*s
GraphicsWindow.PenWidth=0
GraphicsWindow.brushColor="Red"
ell[0]= Shapes.AddEllipse(8,8)
Shapes.SetOpacity(ell[0],50)
Shapes.Move(ell[0], C_X-4, C_Y-4)
For i=1 To Array.GetItemCount(shape)
GraphicsWindow.Penwidth =0
GraphicsWindow.BrushColor = shape[i]["bc"]
GraphicsWindow.penColor = shape[i]["pc"]
If shape[i]["fn"]="ell" Then
shp[i] = Shapes.AddEllipse(shape[i]["wd"]*s, shape[i]["ht"]*s)
ElseIf shape[i]["fn"]="rec" Then
shp[i] = Shapes.Addrectangle(shape[i]["wd"]*s, shape[i]["ht"]*s)
ElseIf shape[i]["fn"]="tri" Then
shp[i] = Shapes.Addtriangle(shape[i]["x1"]*s, shape[i]["y1"]*s,shape[i]["x2"]*s, shape[i]["y2"]*s,shape[i]["x3"]*s, shape[i]["y3"]*s)
EndIf
Shapes.Animate(shp[i], shape[i]["x"]*s+shX, shape[i]["y"]*s+shY, 100)
shapes.Rotate(shp[i],shape[i]["ag"])
EndFor
EndSub

Sub data
shape[1] = "fn=rec;x=29;y=120;wd=10;ht=18;ag=-60;bc=#432F2F;" ' left 1
shape[2] = "fn=rec;x=24;y=90;wd=6;ht=38;ag=15;bc=#432F2F;"
shape[3] = "fn=rec;x=21;y=49;wd=4;ht=45;ag=-18;bc=#432F2F;"
shape[4] = "fn=rec;x=3;y=37;wd=3;ht=20;ag=-70;bc=#432F2F;"
shape[5] = "fn=rec;x=11;y=32;wd=3;ht=20;ag=-10;bc=#432F2F;"
shape[6] = "fn=rec;x=25;y=150;wd=10;ht=18;ag=-60;bc=#432F2F;" ' left 2
shape[7] = "fn=rec;x=8;y=155;wd=6;ht=53;ag=15;bc=#432F2F;"
shape[8] = "fn=rec;x=-6;y=202;wd=4;ht=45;ag=25;bc=#432F2F;"
shape[9] = "fn=rec;x=-13;y=242;wd=3;ht=15;ag=-40;bc=#432F2F;"
shape[10] = "fn=rec;x=17;y=215;wd=10;ht=18;ag=-98;bc=#432F2F;" ' left 3
shape[11] = "fn=rec;x=10;y=229;wd=6;ht=60;ag=8;bc=#432F2F;"
shape[12] = "fn=rec;x=1;y=287;wd=4;ht=38;ag=12;bc=#432F2F;"
shape[13] = "fn=rec;x=1;y=321;wd=3;ht=15;ag=-20;bc=#432F2F;"
shape[14] = "fn=rec;x=99;y=123;wd=10;ht=18;ag=60;bc=#432F2F;" ' right 1
shape[15] = "fn=rec;x=103;y=87;wd=6;ht=38;ag=-15;bc=#432F2F;"
shape[16] = "fn=rec;x=107;y=45;wd=4;ht=45;ag=18;bc=#432F2F;"
shape[17] = "fn=rec;x=121;y=37;wd=3;ht=15;ag=70;bc=#432F2F;"
shape[18] = "fn=rec;x=115;y=30;wd=3;ht=15;ag=10;bc=#432F2F;"
shape[19] = "fn=rec;x=99;y=152;wd=10;ht=18;ag=60;bc=#432F2F;" ' right 2
shape[20] = "fn=rec;x=117;y=153;wd=6;ht=53;ag=-15;bc=#432F2F;"
shape[21] = "fn=rec;x=133;y=202;wd=4;ht=45;ag=-25;bc=#432F2F;"
shape[22] = "fn=rec;x=137;y=241;wd=3;ht=18;ag=40;bc=#432F2F;"
shape[23] = "fn=rec;x=99;y=218;wd=10;ht=18;ag=98;bc=#432F2F;" ' right 3
shape[24] = "fn=rec;x=115;y=225;wd=6;ht=60;ag=-8;bc=#432F2F;"
shape[25] = "fn=rec;x=123;y=283;wd=4;ht=38;ag=-12;bc=#432F2F;"
shape[26] = "fn=rec;x=125;y=321;wd=3;ht=15;ag=20;bc=#432F2F;"
shape[27] = "fn=ell;x=30;y=70;wd=72;ht=260;bc=#D0AF4C;" ' Body
shape[28] = "fn=rec;x=47;y=90;wd=38;ht=33;bc=#028760;"
shape[29] = "fn=ell;x=53;y=70;wd=29;ht=37;bc=#028760;"
shape[30] = "fn=ell;x=34;y=137;wd=28;ht=194;ag=-5;bc=#00A381;" ' wing left
shape[31] = "fn=ell;x=70;y=137;wd=28;ht=194;ag=5;bc=#00A381;" ' wing right
shape[32] = "fn=rec;x=50;y=123;wd=10;ht=100;ag=5;bc=#028760;"
shape[33] = "fn=rec;x=67;y=123;wd=10;ht=100;ag=-5;bc=#028760;"
shape[34] = "fn=ell;x=43;y=79;wd=14;ht=16;ag=3;bc=#17184B;" 'eye
shape[35] = "fn=ell;x=76;y=79;wd=14;ht=16;ag=-3;bc=#17184B;"
shape[36] = "fn=ell;x=47;y=82;wd=7;ht=8;ag=3;bc=#FEF263;"
shape[37] = "fn=ell;x=79;y=82;wd=7;ht=8;ag=-3;bc=#FEF263;"
shape[38] = "fn=rec;x=58;y=57;wd=7;ht=16;ag=-10;bc=#65318E;" 'Tactile sense
shape[39] = "fn=rec;x=45;y=32;wd=6;ht=30;ag=-45;bc=#65318E;"
shape[40] = "fn=rec;x=29;y=0;wd=4;ht=38;ag=-20;bc=#65318E;"
shape[41] = "fn=rec;x=74;y=57;wd=7;ht=16;ag=10;bc=#65318E;"'Tactile sense
shape[42] = "fn=rec;x=85;y=32;wd=6;ht=30;ag=45;bc=#65318E;"
shape[43] = "fn=rec;x=102;y=0;wd=4;ht=38;ag=20;bc=#65318E;"
shape[44] = "fn=rec;x=40;y=110;wd=14;ht=30;ag=8;bc=#FFEA00;" 'Yellow
shape[45] = "fn=rec;x=36;y=140;wd=14;ht=84;ag=-1;bc=#FFEA00;"
shape[46] = "fn=rec;x=44;y=222;wd=12;ht=88;ag=-8;bc=#FFEA00;"
shape[47] = "fn=rec;x=54;y=110;wd=14;ht=30;ag=0;bc=#FFEA00;" 'Yellow
shape[48] = "fn=rec;x=54;y=140;wd=14;ht=82;ag=0;bc=#FFEA00;"
shape[49] = "fn=rec;x=54;y=224;wd=10;ht=88;ag=1;bc=#FFEA00;"
shape[50] = "fn=rec;x=45;y=111;wd=14;ht=30;ag=2;bc=#65318E;" 'Purple
shape[51] = "fn=rec;x=45;y=140;wd=12;ht=84;ag=0;bc=#65318E;"
shape[52] = "fn=rec;x=50;y=225;wd=8;ht=92;ag=-4;bc=#65318E;"
shape[53] = "fn=rec;x=78;y=110;wd=14;ht=30;ag=-8;bc=#FFEA00;" 'Yellow
shape[54] = "fn=rec;x=83;y=140;wd=14;ht=84;ag=-2;bc=#FFEA00;"
shape[55] = "fn=rec;x=80;y=224;wd=12;ht=88;ag=8;bc=#FFEA00;"
shape[56] = "fn=rec;x=68;y=110;wd=14;ht=30;ag=0;bc=#FFEA00;" 'Yellow
shape[57] = "fn=rec;x=68;y=140;wd=14;ht=82;ag=0;bc=#FFEA00;"
shape[58] = "fn=rec;x=68;y=224;wd=10;ht=88;ag=1;bc=#FFEA00;"
shape[59] = "fn=rec;x=74;y=111;wd=14;ht=30;ag=-2;bc=#65318E;" 'Purple
shape[60] = "fn=rec;x=76;y=140;wd=12;ht=84;ag=1;bc=#65318E;"
shape[61] = "fn=rec;x=76;y=225;wd=8;ht=92;ag=4;bc=#65318E;"
L_ang["1L1"]="1=-80;2=-10;3=-30;4=-35;5=-5;"
L_ang["1L2"]="1=-80;2=-60;3=-70;4=-50;"
L_ang["1L3"]="1=-150;2=-130;3=-150;4=-170;"
L_ang["2L1"]="1=-90;2=-110;3=-85;4=-70;5=-125;"
L_ang["2L2"]="1=-110;2=-95;3=-120;4=-140;"
L_ang["2L3"]="1=-100;2=-85;3=-75;4=-120;"
L_ang["1R1"]="1=90;2=80;3=100;4=90;5=170;"
L_ang["1R2"]="1=60;2=80;3=90;4=30;"
L_ang["1R3"]="1=60;2=80;3=70;4=140;"
L_ang["2R1"]="1=60;2=35;3=20;4=50;5=20;"
L_ang["2R2"]="1=70;2=120;3=110;4=180;"
L_ang["2R3"]="1=110;2=120;3=160;4=190;"
L_ang["1L"]="1=-35;2=-45;3=-20;" 'Tactile sense
L_ang["1R"]="1=35;2=45;3=20;"
L_ang["2L"]="1=-5;2=-10;3=-5;"
L_ang["2R"]="1=5;2=10;3=5;"
EndSub