Microsoft Small Basic

Program Listing: djf169
' Challenge of the month August 2012 Graphical Challenge 2 Manta swimming by NaochanON

bubble()
manta()
position()


While "true"
Mantamoving()
bubbling()
Program.Delay(50)
NN=NN+.2*PM
Shapes.SetOpacity(bg,10+NN)
If NN=50 Then
PM=-1
ElseIf NN<10 then
PM=1
EndIf
endwhile

Sub bubbling
For k=1 To 100
by=Math.GetRandomNumber(5)
sby[k]=sby[k]+by/100
Shapes.Move(bbl[k],Shapes.GetLeft(bbl[k]),Shapes.Gettop(bbl[k])-sby[k])
If Shapes.Gettop(bbl[k])<-50 Then
Shapes.Move(bbl[k],Math.GetRandomNumber(1200),Math.GetRandomNumber(900)+600)
sby[k]=0
EndIf
endfor
EndSub


Sub mantamoving
zm= zm+0.01
If 0.5 zm=0
EndIf
For i= 1 To 10
dx= Math.GetRandomNumber(2)
dy= 2-Math.GetRandomNumber(3)
sdx[i]=sdx[i]+dx/100
sdy[i]=sdy[i]+dy/10
For j=1 To 10
Shapes.Move(fig[j][i],Shapes.GetLeft(fig[j][i])-sdx[i],Shapes.Gettop(fig[j][i])+sdy[i])
If j=3 Or j=5 Then
Shapes.Zoom(fig[j][i],1,1-zm )
EndIf
If j=7 Then
Shapes.Rotate(fig[j][i],10-zm*30)
endif
endfor
If Shapes.GetLeft(fig[1][i])<-200 Then
sdx[i]=0
sdy[i]=0
setpositin()
Endif
EndFor
EndSub


Sub manta
for i=1 To 10
GraphicsWindow.BrushColor="Navy"
GraphicsWindow.PenColor ="Navy"
fig[1][i]=Shapes.AddEllipse(18,5)
fig[2][i]=Shapes.AddEllipse(18,5)
color=text.Append("#4040",(30+i*6))
GraphicsWindow.BrushColor=color
GraphicsWindow.PenColor =color
fig[3][i]=Shapes.AddTriangle(36,0,0,50,50,50)
fig[4][i]=Shapes.AddRectangle(50,33)
fig[5][i]=Shapes.AddTriangle(0,0,28,37,50,0)
fig[6][i]=Shapes.AddTriangle(0,0,10,16,0,33)
fig[7][i]=Shapes.AddTriangle(0,0,45,3,0,6)
fig[8][i]=Shapes.AddRectangle(7,10)
fig[9][i]=Shapes.AddRectangle(7,10)
fig[10][i]=Shapes.AddRectangle(5,25)
EndFor
EndSub

Sub position
For i=1 To 10
setpositin()
EndFor
EndSub

Sub setpositin
X0=1000+math.GetRandomNumber(800)
Y0=math.GetRandomNumber(600)
Xt=22
xr=50
yr=40
yt=33
Shapes.Move(fig[1][i],x0,y0+yr+2)
Shapes.Move(fig[2][i],x0,y0+yr+28)
Shapes.Move(fig[3][i],x0+xt,y0)
Shapes.Move(fig[4][i],x0+xt,y0+yr)
Shapes.Move(fig[5][i],x0+xt,y0+yr+yt-8)
Shapes.Move(fig[6][i],x0+xt+xr,y0+yr)
Shapes.Move(fig[7][i],x0+xt+xr,y0+yt+yr/2)
Shapes.Move(fig[8][i],x0+xt-7,y0+yr)
Shapes.Move(fig[9][i],x0+xt-7,y0+yr+yt-7)
Shapes.Move(fig[10][i],x0+xt-4,y0+yr+7)
endsub

Sub bubble
PM=1
GraphicsWindow.Top=10
GraphicsWindow.Left=25
GraphicsWindow.Width=1200
GraphicsWindow.Height=700
GraphicsWindow.BrushColor="Blue"
bg=shapes.AddRectangle(1300,700)
Shapes.SetOpacity(bg,10)
GraphicsWindow.BrushColor="white"
GraphicsWindow.penColor="Lightcyan"
For k=1 To 100
BD=3+Math.GetRandomNumber(7)
bbl[k]=Shapes.AddEllipse(BD,BD)
Shapes.Move(bbl[k],Math.GetRandomNumber(1200),Math.GetRandomNumber(900)+600)
EndFor
EndSub