Microsoft Small Basic

Program Listing: FQQ398
' Challenge of the Month - October 2017 -- Graphics Challenge -- by NaochanON
' Coffee Cup

GraphicsWindow.Width=1200
GraphicsWindow.Height=650
GraphicsWindow.BackgroundColor="#D4DCDA"
GraphicsWindow.Left=20
GraphicsWindow.top=20
init()
Program.Delay(1000)

ddeg=math.pi/120
X0=(shx[3]+shX[1])/2
Y0=(shy[2]+shy[4])/2
While "True"
For M=1 To 4
SName="house"+M
deg[M]=deg[M]+ddeg
For i=1 to 12
shapes.move(shp[SName][i], shape[i]["x"]*s[M]-DR*math.Sin(deg[M])+X0, shape[i]["y"]*s[M]-DR*Math.Cos(deg[M])*rat+Y0)
EndFor
rotation()
EndFor
Program.Delay(100)
endwhile


Sub rotation
_drad=_drad-Math.pi/80
SName="house"+M
c["x"]= shapes.GetLeft(SHP[SName][2])+shape[2]["wd"]/2*s[M]
c["y"]= shapes.Gettop(SHP[SName][2])+shape[2]["ht"]/2*s[M]
_DR= shape[2]["wd"]/2*s[M]*0.7
set_stars()
set_stars2()
set_handle()
EndSub

Sub set_stars
c["x"]= shapes.GetLeft(SHP[SName][2])+shape[2]["wd"]/2*s[M]
c["y"]= shapes.Gettop(SHP[SName][2])+shape[2]["ht"]/2*s[M]
_DR= shape[2]["wd"]/2*s[M]*0.7
_rat=shape[2]["ht"]/shape[2]["wd"]
For k=1 To 10
rad=Math.GetRadians(k*360/10)
shapes.Move(stars[SName][k],c["x"]-_DR*math.Sin(rad+_drad)-sz*s[M]/2,c["y"]-_DR*math.cos(rad+_drad)*_rat-shape[2]["ht"]/2*s[M]*_rat-sz*s[M]/2)
EndFor
set_handle()
EndSub

sub set_stars2
For k=11 To 14
c2["x"]= shapes.GetLeft(SHP[SName][5])+shape[5]["wd"]/2*s[M]
c2["y"]= shapes.Gettop(SHP[SName][5])+shape[5]["ht"]/2*s[M]
_DR=shape[5]["wd"]/2
rad=Math.GetRadians((k-10+2.5)*360/10)
Shapes.Move(stars[SName][k],c2["x"]- _DR*math.Sin(rad)-sz*s[M]/2,c2["y"]-_DR*math.cos(rad)*_rat-sz*s[M]/2)
EndFor
EndSub

Sub set_handle
GraphicsWindow.Title=-math.GetDegrees(_drad)
dL= (shape[5]["wd"]+shape[6]["x3"]+shape[7]["x3"])*s[M]
If math.GetDegrees(_drad)<-90 And math.GetDegrees(_drad)>-270 Then
Shapes.ShowShape(shp[SName][13])
hdeg=shape[13]["deg"]+(math.GetDegrees(_drad)+90)*15/180*2
Shapes.Rotate(shp[SName][13],hdeg)
Else
Shapes.hideShape(shp[SName][13])
hdeg=shape[13]["deg"]
EndIf
shapes.Move(shp[SName][13],Shapes.GetLeft(shp[SName][6])-shape[13]["wd"]/2+dL/2-dL*Math.Sin(_drad)/2,Shapes.Gettop(shp[SName][6])-shape[8]["ht"]*Math.cos(_drad)/2)
Shapes.Zoom(shp[SName][13],(Math.Abs(180+math.GetDegrees(_drad))/90)*s[M],s[M])
EndSub

Sub init
scale = "1=0.7;2=0.9;3=0.8;4=0.6"
shX ="1=120;2=400;3=850;4=450"
shY ="1=150;2=400;3=150;4=50"
DR=(shx[3]-shX[1])/2
rat=(shY[2]-shY[4])/2/DR
For M=1 To 4
shape[1]="fn=el;x=0;y=114;wd=350;ht=92;bc=#640125;pc=#640125;pw=7"
shape[2]="fn=el;x=0;y=100;wd=350;ht=92;bc=#884898;pc=#884898;pw=0"
shape[3]="fn=el;x=100;y=128;wd=150;ht=34;bc=#65318E;pc=#65318E;pw=0"
shape[4]="fn=el;x=124;y=136;wd=100;ht=18;bc=#F2F2B0;pc=#F2F2B0;pw=0"
start=1
end=4
add_shapes()
add_stars()' 10 stars ★
shape[5]="fn=rc;x=124;y=24;wd=100;ht=120;bc=#F2F2B0;pc=#F2F2B0;pw=0"
shape[6]="fn=tr;x=84;y=24;x1=0;y1=0;x2=40;y2=120;x3=40;y3=0;bc=#F2F2B0;pc=#F2F2B0;pw=0"
shape[7]="fn=tr;x=224;y=24;x1=0;y1=0;x2=0;y2=120;x3=40;y3=0;bc=#F2F2B0;pc=#F2F2B0;pw=0"
shape[8]="fn=el;x=82;y=4;wd=182;ht=38;bc=#65318E;pc=#65318E;pw=0"
shape[9]="fn=el;x=102;y=12;wd=140;ht=24;bc=#EAF4FC;pc=#EAF4FC;pw=0"
shape[10]="fn=rc;x=170;y=20;wd=16;ht=16;bc=#E2041B;pc=#E2041B;pw=0"
shape[11]="fn=el;x=164;y=12;wd=26;ht=12;bc=#E2041B;pc=#EAF4FC;pw=2"
shape[12]="fn=el;x=138;y=0;wd=80;ht=28;bc=Transparent;pc=#E2041B;pw=6"
shape[13]="fn=el;x=238;y=44;wd=34;ht=64;bc=Transparent;pc=#007B43;pw=6;deg=20" 'handle
start=5
end=13
add_shapes()
add_stars2() ' 4 stars ◎
deg[M]= Math.ArcTan( (shX[M]-(shX[3]+shX[1])/2)/(shy[M]-(shy[2]+shy[4])/2) )
If (shX[M]-(shX[3]+shX[1])/2)<0 And (shy[M]-(shy[2]+shy[4])/2)>0 Then
deg[M]=deg[M]-Math.pi
EndIf
EndFor
EndSub

Sub add_shapes
SName="house"+M
s[M]=scale[M]
for i=start To end
GraphicsWindow.PenWidth = shape[i]["pw"]
GraphicsWindow.BrushColor = shape[i]["bc"]
GraphicsWindow.penColor = shape[i]["pc"]
If shape[i]["fn"] = "rc" Then
SHP[SName][i] = shapes.AddRectangle(shape[i]["wd"]*s[M], shape[i]["ht"]*s[M])
elseIf shape[i]["fn"] = "el" Then
SHP[SName][i] = shapes.AddEllipse(shape[i]["wd"]*s[M], shape[i]["ht"]*s[M])
ElseIf shape[i]["fn"] = "tr" Then
SHP[SName][i] = shapes.AddTriangle(shape[i]["x1"]*s[M], shape[i]["y1"]*s[M], shape[i]["x2"]*s[M], shape[i]["y2"]*s[M], shape[i]["x3"]*s[M], shape[i]["y3"]*s[M])
ElseIf shape[i]["fn"] = "ln" Then
SHP[SName][i] = shapes.Addline(shape[i]["x1"]*s[M], shape[i]["y1"]*s[M], shape[i]["x2"]*s[M], shape[i]["y2"]*s[M])
EndIf
shapes.Animate(shp[SName][i], shape[i]["x"]*s[M]+shX[M], shape[i]["y"]*s[M]+shY[M], 500)
shapes.Rotate( shp[SName][i],shape[i]["deg"])
EndFor
EndSub

Sub add_stars
sz=20
color="1=#FFDB4F;2=#FFEA00;3=#F08300;4=#EC6D71;5=#E60033;6=#E60033;7=#98D98E;8=#69B076;9=#3EB370;10=#007B43;11=#2CA9E1;12=#007B43;13=#00A3AF;14=#1E50A2;15=#17184B;16=#BC64A4;17=#E95295"
GraphicsWindow.FontSize=sz*s[M]
For k=1 To 10
GraphicsWindow.BrushColor=color[K]
stars[SName][k]=shapes.AddText("★")
EndFor
set_stars()
EndSub

Sub add_stars2
For k=11 To 14
GraphicsWindow.BrushColor=color[K]
stars[SName][k]=shapes.AddText("◎")
EndFor
set_stars2()
EndSub