Microsoft Small Basic

Program Listing: CSS325-1
' December Challenge suggestion - Falling snow CSS325-1
' The next year is Rooster year . So I made Flying ducks.
' Ducks Sounds from YLed

path="http://www.freesfx.co.uk/rx2/mp3s/2/14414_1459970264.mp3"
LRShapes_Init()
LRShapes_Add()
Snow()
FlyingAround()
FlutterDown()
Snowfalling()

Sub Snowfalling
For i=1 To 500
shapes.Animate(sSnow[i],Shapes.GetLeft(sSnow[i]),200+Math.GetRandomNumber(400),2000)
shapes.Animate(LSnow[i],Shapes.GetLeft(LSnow[i]),200+Math.GetRandomNumber(600),2000)
Program.Delay(200)
EndFor
EndSub

Sub Snow
GraphicsWindow.BrushColor="#E6EAE3"
For i=1 To 500
GraphicsWindow.FontSize=Math.GetRandomNumber(20)+2
sSnow[i]= Shapes.AddText("*")
LSnow[i]= Shapes.AddText("※")
shapes.Move(sSnow[i],Math.GetRandomNumber(1200),-100)
shapes.Move(LSnow[i],Math.GetRandomNumber(1200),-100)
EndFor
EndSub

Sub FlutterDown
sounds()
NN=0
while NN<110
NN=NN+1
For j=1 To 10
DX["L"][j]=(Shapes.GetLeft(shp["L"][j][1])-500)/100+5+Math.GetRandomNumber(5)
DY["L"][j]=(500-Shapes.Gettop(shp["L"][j][1]))/100+ 5-Math.GetRandomNumber(10)
DX["R"][j]=(500-Shapes.GetLeft(shp["R"][j][1]))/100+5+Math.GetRandomNumber(5)
DY["R"][j]=(500-Shapes.Gettop(shp["R"][j][1]))/100+ 5-Math.GetRandomNumber(10)
Flapping()
For i=1 to 9
shapes.Move(shp["L"][j][i],Shapes.GetLeft(shp["L"][j][i])-DX["L"][j],Shapes.Gettop(shp["L"][j][i]) +DY["L"][j])
shapes.Move(shp["R"][j][i],Shapes.GetLeft(shp["R"][j][i])+DX["R"][j],Shapes.Gettop(shp["R"][j][i]) +DY["R"][j])
EndFor
endfor
Program.Delay(50)
endwhile
For M=1 To 10 Step 0.2
For j=1 To 10
Shapes.rotate(shp["L"][j][4],9*M)
Shapes.rotate(shp["L"][j][6],9*M)
Shapes.rotate(shp["R"][j][4],-9*M)
Shapes.rotate(shp["R"][j][6],-9*M)
EndFor
Program.Delay(50)
EndFor
EndSub

Sub FlyingAround
sounds()
while LL<2
For j=1 To 10
DX[j]=5+Math.GetRandomNumber(5)
DY[j]= 5-Math.GetRandomNumber(10)
Flapping()
For i=1 to 9
shapes.Move(shp["L"][j][i],Shapes.GetLeft(shp["L"][j][i])-DX[j],Shapes.Gettop(shp["L"][j][i]) +DY[j])
shapes.Move(shp["R"][j][i],Shapes.GetLeft(shp["R"][j][i])+DX[j],Shapes.Gettop(shp["R"][j][i]) +DY[j])
EndFor
endfor
Program.Delay(50)
LX=Shapes.GetLeft( shp["L"][10][1])
RX=Shapes.GetLeft( shp["R"][10][1])
If LX<-200 and RX>1400 Then
sounds()
LL=LL+1
For K=1 to 2
For j=1 to 10
DY[J]=-2.1
Flapping()
For i=1 to 9
Shapes.Move(shp[LR[k]][j][i], Xy0["X"][k] + shape[LR[k]][j][i]["x"]*s1+(j-1)*90, XY0["Y"][K] + shape[LR[k]][j][i]["y"]*s1+Duckdy)
Shapes.Rotate(shp[LR[k]][j][i], shape[LR[k]][j][i]["angle"])
EndFor
endfor
endfor
EndIf
endwhile
EndSub

Sub sounds
Sound.Stop(path)
Sound.Play (path)
EndSub

Sub Flapping
Shapes.Zoom(shp["L"][j][4],1,0.7-DY[j]/7)
Shapes.Zoom(shp["L"][j][6],1,0.7-DY[j]/7)
Shapes.Zoom(shp["R"][j][4],1,0.7-DY[j]/7)
Shapes.Zoom(shp["R"][j][6],1,0.7-DY[j]/7)
EndSub

Sub LRShapes_Init
For j=1 To 10
Shape["R"][j][1] = "func=ell;x=99;y=0;width=56;height=24;bc=#DFCA54;pc=#000000;pw=2;" ' Head
Shape["R"][j][2] = "func=ell;x=129;y=6;width=15;height=6;bc=#DF3954;pc=#000000;pw=2;" ' Eye
Shape["R"][j][3] = "func=ell;x=105;y=12;width=16;height=36;angle=45;bc=#00CA54;pc=#000000;pw=2;" ' Neck
Shape["R"][j][4] = "func=tri;x=50;y=5;x1=21;y1=0;x2=0;y2=57;x3=29;y3=57;bc=#DFCA54;pc=#000000;pw=2;" 'Wing
Shape["R"][j][5] = "func=ell;x=1;y=38;width=108;height=31;bc=#DFCA54;pc=#000000;pw=2;" ' Body
Shape["R"][j][6] = "func=tri;x=37;y=0;x1=7;y1=0;x2=0;y2=57;x3=29;y3=57;bc=#DF8754;pc=#000000;pw=2;" 'Wing
Shape["R"][j][7] = "func=ell;x=144;y=15;width=29;height=9;angle=13;bc=#DF8754;pc=#000000;pw=2;" 'Mouth
Shape["R"][j][8] = "func=line;x=8;y=60;x1=0;y1=8;x2=49;y2=7;pc=#DF3954;pw=2;"
Shape["R"][j][9] = "func=line;x=0;y=70;x1=9;y1=0;x2=0;y2=10;pc=#DF3954;pw=2;"
Shape["L"][j][1] = "func=ell;x=29;y=17;width=61;height=38;bc=#DFCA54;pc=#000000;pw=2;" ' Head
Shape["L"][j][2] = "func=ell;x=46;y=23;width=18;height=9;angle=354;bc=#DF3954;pc=#000000;pw=2;" ' Eye
Shape["L"][j][3] = "func=ell;x=70;y=45;width=16;height=36;angle=313;bc=#00CA54;pc=#000000;pw=2;" ' Neck
Shape["L"][j][4] = "func=tri;x=104;y=4;x1=10;y1=0;x2=0;y2=64;x3=45;y3=64;angle=0;bc=#DFCA54;pc=#000000;pw=2;" ' Wing
Shape["L"][j][5] = "func=ell;x=80;y=58;width=146;height=44;bc=#DFCA54;pc=#000000;pw=2;" ' Body
Shape["L"][j][6] = "func=tri;x=144;y=0;x1=40;y1=0;x2=0;y2=75;x3=46;y3=75;angle=0;bc=#DF8754;pc=#000000;pw=2;" ' Wing
Shape["L"][j][7] = "func=ell;x=0;y=34;width=39;height=14;angle=354;bc=#DFCA54;pc=#000000;pw=2;" ' Beak
Shape["L"][j][8] = "func=line;x=197;y=95;x1=0;y1=0;x2=58;y2=4;pc=#DF3954;pw=4;" ' Leg
Shape["L"][j][9] = "func=line;x=255;y=99;x1=0;y1=0;x2=14;y2=9;pc=#DF3954;pw=4;" ' Leg
EndFor
EndSub

Sub LRShapes_Add
GraphicsWindow.BackgroundColor="#93B69C"
GraphicsWindow.Left=20
GraphicsWindow.top=20
GraphicsWindow.Width=1200
GraphicsWindow.Height=700
GraphicsWindow.BrushColor="#007B43"
GraphicsWindow.FillRectangle(0,200,1200,600)
GraphicsWindow.BrushColor="#2792C3"
lake= Shapes.AddEllipse(1000,300)
shapes.Move(lake,100,300)
'------------------------------------------------------------------------------------------
XY0["X"] ="1=-900;2=1200"
XY0["Y"] ="1=100;2=300"
LR="1=R;2=L"
For k=1 To 2
For j=1 To 10
Duckdy=50-Math.GetRandomNumber(50)
s1=0.4-j*0.01 ' S1
For i = 1 To 9
GraphicsWindow.PenWidth = shape[LR[k]][j][i]["pw"]*s1
GraphicsWindow.PenColor = shape[LR[k]][j][i]["pc"]
GraphicsWindow.BrushColor = shape[LR[k]][j][i]["bc"]
If shape[LR[k]][j][i]["func"] = "ell" Then
shp[LR[k]][j][i] = shapes.AddEllipse(shape[LR[k]][j][i]["width"]*s1, shape[LR[k]][j][i]["height"]*s1)
ElseIf shape[LR[k]][j][i]["func"] = "tri" Then
shp[LR[k]][j][i] = shapes.AddTriangle(shape[LR[k]][j][i]["x1"]*s1, shape[LR[k]][j][i]["y1"]*s1, shape[LR[k]][j][i]["x2"]*s1, shape[LR[k]][j][i]["y2"]*s1, shape[LR[k]][j][i]["x3"]*s1, shape[LR[k]][j][i]["y3"]*s1 )
ElseIf shape[LR[k]][j][i]["func"] = "line" Then
shp[LR[k]][j][i] = shapes.AddLine(shape[LR[k]][j][i]["x1"]*s1, shape[LR[k]][j][i]["y1"]*s1, shape[LR[k]][j][i]["x2"]*s1, shape[LR[k]][j][i]["y2"]*s1)
EndIf
Shapes.Move(shp[LR[k]][j][i], Xy0["X"][k] + shape[LR[k]][j][i]["x"]*s1+(j-1)*90, XY0["Y"][K] + shape[LR[k]][j][i]["y"]*s1+Duckdy)
Shapes.Rotate(shp[LR[k]][j][i], shape[LR[k]][j][i]["angle"])
EndFor
endfor
endfor
EndSub