Microsoft Small Basic

Program Listing:
Embed this in your website
' Challenge of the Month - June 2012 by NaochanON 2012/06/06 RTL937-0
' draft not to exceed 4m ( Ship= L: 50m * W: 5m 100tonnes cargo=5ton )
'

init()
centerling()
Loading()
Vonvoyage()
closewindow()

Sub closewindow
  Program.Delay(3000)
  For k=100 To 50 Step -1
    GraphicsWindow.Width=GraphicsWindow.Width*k/100
    GraphicsWindow.Height=GraphicsWindow.Height*k/100
    Program.Delay(100)
  EndFor
  Program.End()
EndSub


Sub Vonvoyage
  For J=100 To -10 Step -1
    dx=j*10
    moveship()
    cargomove()
    Program.Delay(50)
  EndFor
EndSub

Sub cargomove
  For L=1 To cNumber
    Shapes.Move(scargo[L],shapes.GetLeft(scargo[L])-10,shapes.Gettop(scargo[L]))
    Shapes.Move(sweight[L],shapes.GetLeft(sweight[L])-10,shapes.Gettop(sweight[L]))
  EndFor
EndSub


Sub moveship
  Shapes.Move(tri1,sX-tW+dx,sY-sH+dy)        ' ship left trail
  Shapes.Move(tri2,sX+sW+dx,sY-sH+dy)        ' ship right head
  Shapes.Move(ship,sX+dx,sY-sH+dy)           ' ship body
  For i=1 To 9
    Shapes.Move(window[i],sx+i*50+dx,sy-sH+15+dy) ' ship window
  EndFor
  Shapes.Move(draft,sX+dx,sY-sH+60+dy)     ' draft line 2*20=40 100-40=60
  Shapes.Move(smsg,sx+dx,560)              ' n H message
EndSub


Sub Loading
  For K= 1 To cNumber
    cargoloading()
  EndFor
  Sound.PlayChimeAndWait()
EndSub

Sub cargoloading
  '------------- Loader Cargo Weight message Move Left -----------------------------------------
  For MM=1 To 80
    X=cX-11*MM  +MM*Math.Remainder((K-1),6)*CL/80
    Shapes.Move(sloader,X,100)                   ' loader
    For j=1 To 2
      Shapes.Move(swire[j],x+(j-1)*cL,125)       ' wire
    EndFor
    Shapes.Move(scargo[k],X,cY)                  ' cargo
    Shapes.Move(sweight[k],X+2,cY+cl/5)          ' weight message
    Program.Delay(50)
  EndFor
  '------------- Cargo ( Weight message ) Loading ------------------------------------------------------
  dy=K*2
  YN= math.Floor((k-1)/6)+1
  Shapes.Animate(scargo[k],X,cY+200-30*YN+dy,1000)           ' cargo
  Shapes.Animate(sweight[k],X+2,cY+cl/5+200-30*YN+dy,1000)   ' weight message
  Program.Delay(1000)
  cargosink()                                  ' cargo sinks
  moveship()                                   ' ship sinks
  n=k*10
  w=n*5
  H=0.4+0.2*K
  msg= " Draft H=4m "+LF+"Buoyancy = S*H*ρ = 50*5*H*ρ = 100ton + W * n "+LF
  msg=msg+"ρ=1 W=5ton -----> n=(50*5*H-100)/5 "+LF
  msg=msg+ " H= "+H+ " m -----> n = "+n+" pieces (Cargo= "+5*n +" tonnes)"
  Shapes.SetText(smsg,msg)
  Sound.PlayClickAndWait()
  Sound.PlayClickAndWait()
  '------------- Loader Cargo Weight message Move right -----------------------------
  For MM=80 To 1  Step -1
    X=cX-10*MM  +MM*Math.Remainder((K-1),6)*CL/80
    Shapes.Move(sloader,X,100)
    For j=1 To 2
      Shapes.Move(swire[j],x+(j-1)*cL,125)
    EndFor
    Program.Delay(50)
  EndFor
EndSub

Sub cargosink
  For L=1 To K
    cT= Shapes.GetTop(scargo[L])           ' cargo top Y
    wT= Shapes.GetTop(sweight[L])          ' weight message top Y
    cX2= Shapes.GetLeft(scargo[L])         ' cargo left X
    wx2= Shapes.GetLeft(sweight[L])        ' weight message top X
    Shapes.Move(scargo[L],cX2,cT+2)
    Shapes.Move(sweight[L],wX2,wT+2)
  EndFor
EndSub

Sub centerling
  For J=1 To 100
    dx=j*10
    moveship()
    Program.Delay(50)
  EndFor
EndSub

Sub init
  GraphicsWindow.Hide()
  GraphicsWindow.Top=10
  GraphicsWindow.Left=50
  GraphicsWindow.Width=1200
  GraphicsWindow.Height=800
  '-------------------- Title & Background ---------- Denmark quay ?---------------
  url="http://farm4.static.flickr.com/3239/2842722415_e8c25c879c.jpg"
  GraphicsWindow.DrawResizedImage(url,0,-100,1200,594)
  GraphicsWindow.Title="Shipping at here ......... "+url
  ' ----------------------------------------------------------------------------------------------
  shipimage()       ' ship
  message()         ' message
  CargoLoader()     ' cargo loader
  moveship()        ' ship location
  GraphicsWindow.Show()
EndSub

Sub shipimage
  ' ------------------- ship image ----------------------------------
  ShipWeight=100
  ShipWidth=5
  sW=500           ' ship length
  sH=100           ' ship height
  sX=-700          ' ship position -X initial -600
  sY=500           ' sea surface -Y
  tW=20            ' head or trail triangle width
  tH=sH-4          ' head or trail triangle height
  dx=0             ' horizontal move length
  dy=0             ' verticl move length
  GraphicsWindow.BrushColor="darkgreen"
  GraphicsWindow.PenColor="darkgreen"
  tri1=Shapes.AddTriangle(0,0,tW,0,tW,tH)  ' trail
  tri2=Shapes.AddTriangle(0,0,tW,0,0,tH)   ' head
  ship= Shapes.AddRectangle(sW,sH)        ' body

  GraphicsWindow.BrushColor="lightcyan"
  GraphicsWindow.PenColor="Red"
  For i=1 To 9
    window[i]= Shapes.AddEllipse(15,15)   ' window
  EndFor
  draft= Shapes.AddLine(0,0,sw,0)
  ' ------------------- image of under sea surface ----------------------------
  GraphicsWindow.BrushColor="Blue"
  GraphicsWindow.PenColor="Blue"
  For i=0 To 5
    Blue[i]= Shapes.AddRectangle(1200,500)
    Shapes.Move(blue[i],0,494+10*i*i)
    Shapes.SetOpacity(blue[i],30+10*I)
  EndFor
EndSub

Sub message                    ' ------------ Buoyancy -------------------------------------
  W=5      ' 5 ton
  H=0.4      ' initial 100/50/5=0.4 m
  LF= Text.GetCharacter(10)
  GraphicsWindow.BrushColor="White"
  GraphicsWindow.FontItalic="True"
  GraphicsWindow.FontSize=25
  n= 0             ' (50*5*H-100)/5 ' 50*5*H = 100+W*n
  msg= " Draft H=4m "+LF+"Buoyancy = S*H*ρ = 50*5*H*ρ = 100ton + W * n "+LF
  msg=msg+"ρ=1 W=5ton -----> n=(50*5*H-100)/5 "+LF
  msg=msg+ " H= "+H+ " m -----> n = "+n+" pieces (Cargo= "+5*n +" tonnes)"
  smsg=Shapes.AddText(msg)
  cNumber= (50*5*4-100)/(5*10)
EndSub

Sub CargoLoader
  ' ------------------- Cargo ---------------------------------- 2x2x5 m
  cX=1250
  cY=sy-300             ' cY=200
  cL=60
  For K=1 To cNumber
    GraphicsWindow.BrushColor="khaki"
    GraphicsWindow.PenColor="Brown"
    scargo[k]=Shapes.AddRectangle(cL,30)
    Shapes.Move(scargo[k],cX,cY)
    Shapes.SetOpacity(scargo[k],65)
    GraphicsWindow.BrushColor="Navy"
    GraphicsWindow.FontSize=12
    sweight[k]=Shapes.AddText("10p=50t")
    Shapes.Move(sweight[k],cX+2,cY+cl/5)
  EndFor
  ' ------------------- Loader ----------------------------------
  GraphicsWindow.BrushColor="darkgreen"
  sLoader=Shapes.AddRectangle(1000,25)         ' loader
  Shapes.Move(sloader,cX,100)
  GraphicsWindow.PenColor="Green"
  GraphicsWindow.PenWidth=3
  For i=1 To 2
    swire[i]= Shapes.AddLine(0,0,0,75)        ' wire
    Shapes.Move(swire[i],cx+(i-1)*cL,125)
  EndFor
endsub

Copyright (c) Microsoft Corporation. All rights reserved.