Microsoft Small Basic

Program Listing: MTC753
' Challenge of the Month - October 2017 -- Graphics Challenge -- by NaochanON
' Ferris wheel and train
GraphicsWindow.BackgroundColor="#D8E698"
GraphicsWindow.Width=1200
GraphicsWindow.Height=750
GraphicsWindow.Left=5
GraphicsWindow.Top=2

makeshapes()
init()
add_shapes()
dx=5 ' moving length X-direction
ds=dx*360/shape[12]["wd"]/math.pi ' rotating angle
dy=0

While "True"
wds=2
For ii=1 To Fn
wangle[ii]=wangle[ii]+wds
setting()
EndFor

for i=1 To Array.GetItemCount(shape)
Shapes.Move(shp[SName][i],Shapes.GetLeft(shp[SName][i])+dx,Shapes.Gettop(shp[SName][i])+dy)
If i>19 then
angle[i]=angle[i]+ds
shapes.Rotate(shp[SName][i],angle[i])
endif
EndFor
GraphicsWindow.Title=Shapes.GetLeft(shp[SName][8])
If (math.abs(300-Shapes.GetLeft(shp[SName][8]))<25) Or (math.abs(650-Shapes.GetLeft(shp[SName][8]))<25) Or (math.abs(900-Shapes.GetLeft(shp[SName][8]))<25) Then
NN=NN+1
Shapes.Move(smoke[NN],Shapes.GetLeft(shp[SName][8]),Shapes.GetTop(shp[SName][8]))
EndIf
For k=1 To NN
Shapes.Move(smoke[k],Shapes.GetLeft(smoke[k])-dx-(15-k)/3*dx/math.Abs(dx),Shapes.Gettop(smoke[k])-9)
shapes.Zoom(smoke[k],(NN-k)/2,(NN-k)/3)
EndFor
If Shapes.Gettop(smoke[NN])<-30 Then
For k=1 to NN
Shapes.Move(smoke[k],-500,-500)
shapes.Zoom(smoke[k],1,1)
endfor
endif
If (dx>0 and Shapes.GetLeft(shp[SName][16])>1250) or (dx<0 and Shapes.GetLeft(shp[SName][16])<-50) Then
NN=0
dx=-dx
ds=dx*360/shape[12]["wd"]/math.pi ' rotating angle
pm=(625- shapes.GetTop(shp[SName][16]))/Math.Abs(625- shapes.GetTop(shp[SName][16]))
dy=pm*math.GetRandomNumber(50)
return()
EndIf
dy=0
Program.Delay(100)
endwhile

Sub setting
rad=math.GetRadians(wangle[ii])
Shapes.move(shp[1][ii],x0+DR[0]*Math.Sin(rad)-5,y0-DR[0]*Math.cos(rad)-5)
Shapes.move(shp[2][ii],Shapes.GetLeft(shp[1][ii])-(DR[2]-DR[1])/2,Shapes.Gettop(shp[1][ii])+DR[1])
Shapes.move(shp[3][ii],Shapes.GetLeft(shp[1][ii])-DR[0]*Math.Sin(rad)/2,Shapes.Gettop(shp[1][ii])+DR[1]/2-DR[0]*(1-Math.Cos(rad))/2)
Shapes.Rotate(shp[3][ii],wangle[ii])
endsub

Sub makeshapes
Fn=16 ' Max 16
color="1=#FFDB4F;2=#FFEA00;3=#F08300;4=#EC6D71;5=#2CA9E1;6=#3EB370;7=#E65033;8=#E60033;9=#98D98E;10=#69B076;11=#2CAAE1;12=#2C7B43;13=#01A3AF;14=#1E50A2;15=#17184B;16=#BC64A4;17=#E95295"
DR="0=250;1=10;2=80;3=10;4=100;5=380;6=75"
x0=500
y0=20+DR[0]
'Boxes
For ii=1 To Fn
GraphicsWindow.BrushColor=color[ii] 'GraphicsWindow.GetRandomColor()
GraphicsWindow.penColor=color[ii+1] 'GraphicsWindow.GetRandomColor()
GraphicsWindow.PenWidth=2
deg=360/Fn*(ii-1)
wangle[ii]=deg ' initial angle
shp[1][ii]=Shapes.AddEllipse(DR[1],DR[1])
shp[2][ii]=Shapes.AddEllipse(DR[2],DR[2]*0.75)
shp[3][ii]=Shapes.AddRectangle(DR[3],DR[0])
setting()
EndFor
' Frame
deg=360/12
rad=math.GetRadians(deg)
GraphicsWindow.BrushColor="#007B43"
GraphicsWindow.penColor="#2F5D50"
shp[4][1]=Shapes.AddEllipse(DR[4],DR[4])
Shapes.Move(shp[4][1],x0-DR[4]/2,y0+DR[1]-DR[4]/2)
shp[5][1]=Shapes.AddRectangle(DR[1]*2,DR[5])
Shapes.Move(shp[5][1],Shapes.GetLeft(shp[4][1])+DR[4]/2-DR[1]-DR[5]*Math.Sin(rad)/2,Shapes.Gettop(shp[4][1])+DR[4]/2-DR[5]*(1-Math.Cos(rad))/2)
Shapes.Rotate(shp[5][1],deg)
shp[5][2]=Shapes.AddRectangle(DR[1]*2,DR[5])
Shapes.Move(shp[5][2],Shapes.GetLeft(shp[4][1])+DR[4]/2-DR[1]+DR[5]*Math.Sin(rad)/2,Shapes.Gettop(shp[4][1])+DR[4]/2-DR[5]*(1-Math.Cos(rad))/2)
Shapes.Rotate(shp[5][2],-deg)
shp[5][3]=Shapes.AddRectangle(DR[5]/2,DR[1]*2)
Shapes.Move(shp[5][3],x0-DR[5]/2/2,y0+DR[5]/2-DR[1]*2)
GraphicsWindow.BrushColor="#C1D8AC"
shp[6][1]=Shapes.AddEllipse(DR[6],DR[6])
Shapes.Move(shp[6][1],x0-DR[6]/2,y0+DR[1]-DR[6]/2)
' ground
GraphicsWindow.BrushColor="#3EB370"
GraphicsWindow.FillRectangle(0,Shapes.Gettop(shp[5][1])+DR[5]-(DR[5]*(1-Math.Cos(rad))/2),1200,400)
EndSub

Sub return
For j=1 To Array.GetItemCount(shape)
if dx<0 then
Shapes.Move(shp[SName][j],Shapes.GetLeft(shp[SName][j])-2*shape[j]["x"]-shape[j]["wd"]+dL,Shapes.Gettop(shp[SName][j])+dy)
Else
Shapes.Move(shp[SName][j],Shapes.GetLeft(shp[SName][j])+2*shape[j]["x"]+shape[j]["wd"]-dL,Shapes.Gettop(shp[SName][j])+dy)
EndIf
EndFor
EndSub

Sub add_shapes
SName="train"
ss=scale[1]
for i=1 To Array.GetItemCount(shape)
GraphicsWindow.PenWidth = shape[i]["pw"]
GraphicsWindow.BrushColor = shape[i]["bc"]
GraphicsWindow.penColor = shape[i]["pc"]
If shape[i]["fn"]="el" Then
shp[SName][i] = Shapes.AddEllipse(shape[i]["wd"]*ss, shape[i]["ht"]*ss)
ElseIf shape[i]["fn"]="rec" Then
shp[SName][i] = Shapes.AddRectangle(shape[i]["wd"]*ss, shape[i]["ht"]*ss)
EndIf
Shapes.Animate(shp[SName][i], shape[i]["x"]*ss+shX[1], shape[i]["y"]*ss+shY[1], 500)
shapes.Rotate(shp[SName][i],shape[i]["deg"])
angle[i]=shape[i]["deg"]
EndFor
EndSub

Sub init
scale[1]=1
shX[1]=100
shy[1]=600

Shape[1]="fn=rec;x=120;y=40;wd=120;ht=24;bc=#EA5506;pc=#EA5506;pw=0"
Shape[2]="fn=rec;x=120;y=64;wd=120;ht=24;bc=#D7003A;pc=#D7003A;pw=0"
Shape[3]="fn=rec;x=40;y=16;wd=86;ht=74;bc=#E95464;pc=#E95464;pw=0"
Shape[4]="fn=rec;x=58;y=22;wd=45;ht=34;bc=#EAF4FC;pc=#17184B;pw=2"
Shape[5]="fn=rec;x=14;y=78;wd=22;ht=14;bc=#726D40;pc=#726D40;pw=0"
Shape[6]="fn=rec;x=32;y=0;wd=98;ht=16;bc=#89C3EB;pc=#88CB7F;pw=3"
Shape[7]="fn=rec;x=150;y=18;wd=16;ht=24;bc=#89C3EB;pc=#89C3EB;pw=0"
Shape[8]="fn=rec;x=186;y=12;wd=22;ht=30;bc=#89C3EB;pc=#89C3EB;pw=0"
Shape[9]="fn=rec;x=146;y=12;wd=24;ht=6;bc=#88CB7F;pc=#88CB7F;pw=3"
Shape[10]="fn=rec;x=182;y=6;wd=30;ht=6;bc=#88CB7F;pc=#88CB7F;pw=3"
Shape[11]="fn=el;x=230;y=40;wd=22;ht=48;bc=#FEF263;pc=#007B43;pw=3"
Shape[12]="fn=el;x=22;y=68;wd=64;ht=64;bc=#EB6EA5;pc=#A59564;pw=8"
Shape[13]="fn=el;x=88;y=68;wd=64;ht=64;bc=#EB6EA5;pc=#A59564;pw=8"
Shape[14]="fn=el;x=154;y=86;wd=46;ht=46;bc=#EB6EA5;pc=#A59564;pw=6"
Shape[15]="fn=el;x=202;y=86;wd=46;ht=46;bc=#EB6EA5;pc=#A59564;pw=6"
Shape[16]="fn=el;x=0;y=66;wd=18;ht=40;bc=#E60033;pc=#E60033;pw=0"
Shape[17]="fn=el;x=80;y=22;wd=10;ht=16;bc=#17184B;pc=#17184B;pw=0"
Shape[18]="fn=el;x=77;y=38;wd=14;ht=19;bc=#17184B;pc=#17184B;pw=0"
Shape[19]="fn=rec;x=85;y=42;wd=14;ht=4;bc=#17184B;pc=#17184B;pw=0"
Shape[20]="fn=rec;x=52;y=76;wd=4;ht=48;bc=#007B43;pc=#007B43;pw=0"
Shape[21]="fn=rec;x=52;y=76;wd=4;ht=48;bc=#007B43;pc=#007B43;pw=0;deg=90"
Shape[22]="fn=rec;x=118;y=76;wd=4;ht=48;bc=#007B43;pc=#007B43;pw=0"
Shape[23]="fn=rec;x=118;y=76;wd=4;ht=48;bc=#007B43;pc=#007B43;pw=0;deg=90"
Shape[24]="fn=rec;x=176;y=90;wd=4;ht=38;bc=#007B43;pc=#007B43;pw=0"
Shape[25]="fn=rec;x=176;y=90;wd=4;ht=38;bc=#007B43;pc=#007B43;pw=0;deg=90"
Shape[26]="fn=rec;x=224;y=90;wd=4;ht=38;bc=#007B43;pc=#007B43;pw=0"
Shape[27]="fn=rec;x=224;y=90;wd=4;ht=38;bc=#007B43;pc=#007B43;pw=0;deg=90"
dL= shape[11]["x"]-shape[16]["x"]+100 ' mirror point

GraphicsWindow.BrushColor="#949495"
GraphicsWindow.PenColor="#727171"
For i= 1 To 40
smoke[i]= Shapes.AddEllipse(18,12)
Shapes.Move(smoke[i],-100,-100)
EndFor
EndSub