Microsoft Small Basic

Program Listing:
Embed this in your website
' Aquarium
x = 110
y = 60
width = 400
height = 300
depth = 230
' draw aqarium
GraphicsWindow.BackgroundColor = "LightGray"
GraphicsWindow.PenColor = "White"
GraphicsWindow.DrawRectangle(x, y, width, height)
' draw caption
GraphicsWindow.BrushColor = "DimGray"
caption = "DeepSkyBlue Fish"
wCaption = (Text.GetLength(caption) + 2) * 7
GraphicsWindow.FillRectangle(x + (width - wCaption) / 2, y + height + 10, wCaption, 16)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawBoundText(x + (width - wCaption) / 2 + 7, y + height + 10, wCaption, caption)
AddBall()
AddBubbles()
AddFish()
AddWater()
StartTimer()

Sub AddFish
  nFish = 3
  hFish = 20  ' height
  For i = 1 To nFish
    Stack.PushValue("local", x)
    Stack.PushValue("local", y)
    dirFish[i] = 1 ' direction
    x = x + 10 + Math.GetRandomNumber(width - 10 - hFish * 3)
    y = y + height - hFish - Math.GetRandomNumber(depth - hFish)
    GraphicsWindow.PenColor = "DodgerBlue"      ' tail color
    GraphicsWindow.BrushColor = "DeepSkyBlue"   ' tail color
    oFishTail[i] = Shapes.AddRectangle(hFish * 1.5, hFish * 0.5)
    xFishTail[i] = x
    yFishTail[i] = y + hFish * 0.25
    Shapes.Move(oFishTail[i], xFishTail[i], yFishTail[i])
    GraphicsWindow.PenColor = "DodgerBlue"      ' fish color
    GraphicsWindow.BrushColor = "DeepSkyBlue"   ' fish color
    oFishBody[i] = Shapes.AddEllipse(hFish * 2, hFish)
    xFishBody[i] = x + hFish
    yFishBody[i] = y
    Shapes.Move(oFishBody[i], xFishBody[i], yFishBody[i])
    GraphicsWindow.PenColor = "White"           ' eye color
    GraphicsWindow.BrushColor = "Black"         ' eye color
    oFishEye[i] = Shapes.AddEllipse(hFish * 0.5, hFish * 0.5)
    xFishEye[i] = x + hFish * 2.25
    yFishEye[i] = y + hFish * 0.25
    Shapes.Move(oFishEye[i], xFishEye[i], yFishEye[i])
    y = Stack.PopValue("local")
    x = Stack.PopValue("local")
  EndFor
EndSub

Sub MoveFish
  distance = 20
  For i = 1 To nFish
    xFishEye[i] = xFishEye[i] + distance * dirFish[i]
    xFishBody[i] = xFishBody[i] + distance * dirFish[i]
    xFishTail[i] = xFishTail[i] + distance * dirFish[i]
    If xFishBody[i] < x Then
      xFishBody[i] = x + 10 + hFish
      xFishEye[i] = xFishBody[i] + hFish * 1.25
      xFishTail[i] = xFishBody[i] - hFish
      dirFish[i] = 1
    ElseIf x + width - 10 < xFishBody[i] + hFish * 3 Then
      xFishBody[i] = x + width - hFish * 3 - 10
      xFishEye[i] = xFishBody[i] + hFish * 0.25
      xFishTail[i] = xFishBody[i] + hFish * 1.5
      dirFish[i] = -1
    EndIf
    Shapes.Move(oFishEye[i], xFishEye[i], yFishEye[i])
    Shapes.Move(oFishBody[i], xFishBody[i], yFishBody[i])
    Shapes.Move(oFishTail[i], xFishTail[i], yFishTail[i])
  EndFor
EndSub

Sub AddBubbles
  nBubbles = 10
  GraphicsWindow.PenColor = "White"
  GraphicsWindow.BrushColor = "White"
  For i = 1 To nBubbles
    oBubbles[i] = Shapes.AddEllipse(5, 5)
    xBubbles[i] = x + 60 + Math.GetRandomNumber(50)
    yBubbles[i] = y + height - 25 - Math.GetRandomNumber(depth - 25)
  EndFor
EndSub

Sub MoveBubbles
  up = 40
  For i = 1 To nBubbles
    yBubbles[i] = yBubbles[i] - up
    If yBubbles[i] < y + height - depth Then
      xBubbles[i] = x + 60 + Math.GetRandomNumber(50)
      yBubbles[i] = y + height - 25 - Math.GetRandomNumber(up)
    EndIf
    Shapes.Move(oBubbles[i], xBubbles[i], yBubbles[i])
  EndFor
EndSub

Sub AddBall
  Stack.PushValue("local", x)
  Stack.PushValue("local", y)
  GraphicsWindow.PenColor = "DarkGray"
  GraphicsWindow.BrushColor = "DarkGray"
  oAquarium = Shapes.AddEllipse(50, 50)
  x = x + 60
  y = y + height - 50
  Shapes.Move(oAquarium, x, y)
  Shapes.SetOpacity(oAquarium, 50)
  y = Stack.PopValue("local")
  x = Stack.PopValue("local")
EndSub

Sub AddWater
  Stack.PushValue("local", y)
  y = y + height - depth
  GraphicsWindow.PenColor = "White"
  GraphicsWindow.BrushColor = "Aqua"
  oAquarium = Shapes.AddRectangle(width, depth)
  Shapes.Move(oAquarium, x, y)
  Shapes.SetOpacity(oAquarium, 10)
  y = Stack.PopValue("local")
EndSub

Sub StartTimer
  Timer.Interval = 200
  Timer.Tick = OnTick
EndSub

Sub OnTick
  MoveBubbles()
  MoveFish()
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.