Microsoft Small Basic

Program Listing:
Embed this in your website
' Challenge of the month Feb 2013 Fun Clock by NaochanON 2013/02/12 TDG816-0

Shapes_Init()
Shapes_Add()
drops()
Shapes_crab()
Shapes_Add()
Crab_enter()
Clock_shape()

While "true"
  DH="1="+(100+Clock.Second)+";2="+(100+Clock.Minute)+";3="+(100+Clock.Hour)  ' Make clock array DH[ ]
  water_drop()
  Water_Height()
  shapes.SetText(smsg["Date"],Clock.Date)
  shapes.SetText(smsg["Sec"],Text.GetSubText(DH[1],2,2))  ' Sec
  shapes.SetText(smsg["Min"],Text.GetSubText(DH[2],2,2))  ' Min
  shapes.SetText(smsg["Hr"],Text.GetSubText(DH[3],2,2))   ' Hr
  crab_Moving()
  Program.Delay(50)
endwhile

Sub Crab_Moving
  For k=start To end
    Shapes.Move(shape[k]["obj"],Shapes.GetLeft(shape[k]["obj"])+cddx,Shapes.Gettop(shape[k]["obj"])+cddy)
  EndFor
  If shapes.GetLeft(shape[52]["obj"])< Shapes.GetLeft(shape[3]["obj"])+5 Then
    cddx=-cddx
  elseIf Shapes.GetLeft(shape[2]["obj"])-10<(Shapes.GetLeft(shape[25]["obj"])) Then
    cddx=-cddx
  elseif  shapes.Gettop(shape[52]["obj"])< Shapes.Gettop(shape[3]["obj"])+shape[3]["height"]/2 Then
    cddy=-cddy
  elseif  Shapes.Gettop(shape[3]["obj"])+shape[3]["height"]<shapes.Gettop(shape[46]["obj"])+6 Then
    cddy=-cddy
  EndIf
EndSub

Sub water_drop
  '---------------------------------------- second drop -----------------
  NN=NN+1
  ddy=NN/20*shape[1]["height"]
  Shapes.move(drop[1],shapes.GetLeft(shape[11]["obj"]),Shapes.GetTop(shape[11]["obj"])+ddY)  ' second drop
  '----------------------------------------- Water tank(second) height -------------------
  If DH[1]>=130 Then
    Shapes.rotate(shape[5]["obj"],-90)        ' Open Water faucet 1
    Shapes.move(drop[2],shapes.GetLeft(shape[4]["obj"])-4,Shapes.GetTop(shape[4]["obj"])+ddY)   ' Minute drop
    Shapes.move(drop[3],shapes.GetLeft(shape[4]["obj"])+2,Shapes.GetTop(shape[4]["obj"])+ddY+5) ' Minute drop
  else
    Shapes.rotate(shape[5]["obj"],0)        ' Close Water faucet 1
  EndIf
  '----------------------------------------- Water tank(Minute) height -------------------
  If DH[2]>=130 Then
    Shapes.rotate(shape[7]["obj"],-90)        ' Open Water faucet 2
    For j=4 To 7
      Shapes.move(drop[j],shapes.GetLeft(shape[6]["obj"])-9+4*(j-4),Shapes.GetTop(shape[6]["obj"])+ddY+6*(j-3))   ' Hour drop
    endfor
  else
    Shapes.rotate(shape[7]["obj"],0)        ' Close Water faucet 2
  EndIf
  '----------------------------------------- Water tank(Hour) height -------------------
  If DH[3]>=112 Then
    Shapes.rotate(shape[9]["obj"],-90)        ' Open Water faucet 2
    For j=8 To 11
      Shapes.move(drop[j],shapes.GetLeft(shape[8]["obj"])-9+4*(j-8),Shapes.GetTop(shape[8]["obj"])+ddY+6*(j-7))   ' Hour drop
    endfor
  else
    Shapes.rotate(shape[9]["obj"],0)        ' Close Water faucet 3
  EndIf
  '----------------------------------------- return drops -------------------
  If NN=20 Then
    Shapes.move(drop[1],shapes.GetLeft(shape[11]["obj"]),Shapes.GetTop(shape[11]["obj"])+10)    ' second drop
    Shapes.move(drop[2],shapes.GetLeft(shape[4]["obj"])-4,Shapes.GetTop(shape[4]["obj"])+10)    ' From second tank
    Shapes.move(drop[3],shapes.GetLeft(shape[4]["obj"])-4,Shapes.GetTop(shape[4]["obj"])+10)    ' From second tank
    For j=4 To 7
      Shapes.move(drop[j],shapes.GetLeft(shape[6]["obj"])-4,Shapes.GetTop(shape[6]["obj"])+10)  ' From Minute tank
    endfor
    For j=8 To 11
      Shapes.move(drop[j],shapes.GetLeft(shape[8]["obj"])-4,Shapes.GetTop(shape[8]["obj"])+10)  ' From Hour tank
    endfor
    NN=0
  EndIf
EndSub

Sub Water_Height
  '----------------------- Second water tank -------------------------------
  If DH[1]<130 Then         ' within 30sec
    WH1=DH[1]+30-100
  ElseIf DH[1]>=130 then    ' over 30sec
    WH1=60-(DH[1]-30-100)
  endif
  Shapes.Zoom(shape[15]["obj"],1,WH1/60)
  Shapes.Move(shape[15]["obj"],Shapes.GetLeft(shape[15]["obj"]),shy+shape[1]["y"]+(1-WH1/60)*shape[1]["height"]/2)
  '----------------------- Minute water tank -------------------------------
  If DH[2]<130 Then          ' within 30minute
    WH2=DH[2]+30-100
  ElseIf DH[2]>=30 then      ' over 30minute
    WH2=60-(DH[2]-30-100)
  endif
  Shapes.Zoom(shape[16]["obj"],1,(WH2/60))
  Shapes.Move(shape[16]["obj"],Shapes.GetLeft(shape[16]["obj"]),shy+shape[2]["y"]+(1-(WH2/60))*shape[2]["height"]/2)
  '----------------------- Hour water tank -------------------------------
  If DH[3]<112 Then           ' within 12Hour
    WH3=DH[3]+12-100
  ElseIf DH[3]>=112 then      ' over 12Hour
    WH3=24-(DH[3]-12-100)
  endif
  Shapes.Zoom(shape[17]["obj"],1,(WH3/24))
  Shapes.Move(shape[17]["obj"],Shapes.GetLeft(shape[17]["obj"]),shy+shape[3]["y"]+(1-(WH3/24))*shape[3]["height"]/2)
EndSub

Sub drops
  GraphicsWindow.BrushColor="#00CED1"
  GraphicsWindow.PenColor="#00CED1"
  drop[1]=Shapes.AddEllipse(5,8)
  shapes.Move(drop[1],shapes.GetLeft(shape[10]["obj"]),Shapes.GetTop(shape[10]["obj"])+10)  ' Second drop
  For j=2 To 3
    drop[j]=Shapes.AddEllipse(5,8)
    shapes.Move(drop[j],shapes.GetLeft(shape[4]["obj"]),Shapes.GetTop(shape[4]["obj"])+10)  ' Minute Drop
  endfor
  For j=4 To 7
    drop[j]=Shapes.AddEllipse(5,8)
    shapes.Move(drop[j],shapes.GetLeft(shape[6]["obj"]),Shapes.GetTop(shape[6]["obj"])+10)  ' hour Drop
  endfor
  For j=8 To 11
    drop[j]=Shapes.AddEllipse(5,8)
    shapes.Move(drop[j],shapes.GetLeft(shape[8]["obj"]),Shapes.GetTop(shape[8]["obj"])+10)  ' wasted drop
  endfor
EndSub

Sub Clock_shape
  '------------------------------- Clock data display -------------------------------
  GraphicsWindow.BrushColor="Lightcyan"
  GraphicsWindow.FontSize=24
  smsg["Date"]=Shapes.AddText(" ")
  Shapes.Move(smsg["Date"],100,20)
  GraphicsWindow.FontSize=20
  smsg["Sec"]=Shapes.AddText(" ")
  Shapes.Move(smsg["Sec"],shx+shape[1]["x"]+shape[1]["width"]/3-4,shy+shape[1]["y"]+2*shape[1]["height"]/3)
  smsg["Min"]=Shapes.AddText(" ")
  Shapes.Move(smsg["Min"],shx+shape[2]["x"]+shape[2]["width"]/3,shy+shape[2]["y"]+2*shape[2]["height"]/3)
  smsg["Hr"]=Shapes.AddText(" ")
  Shapes.Move(smsg["Hr"],shx+shape[3]["x"]+shape[3]["width"]/3,shy+shape[3]["y"]+2*shape[3]["height"]/3)
  GraphicsWindow.Show()
EndSub

Sub Shapes_Add
  '------------------------------- Water Clock and Crab -------------------------------
  For i = start To Array.GetItemCount(shape)
    GraphicsWindow.PenWidth = shape[i]["pw"]*s
    GraphicsWindow.PenColor = shape[i]["pc"]
    GraphicsWindow.BrushColor = shape[i]["bc"]
    If shape[i]["func"] = "rect" Then
      shape[i]["obj"] = Shapes.AddRectangle(shape[i]["width"]*s, shape[i]["height"]*s)
    ElseIf shape[i]["func"] = "ell" Then
      shape[i]["obj"] = Shapes.AddEllipse(shape[i]["width"]*s, shape[i]["height"]*s)
    ElseIf shape[i]["func"] = "tri" Then
      shape[i]["obj"] = Shapes.AddTriangle(shape[i]["x1"]*s, shape[i]["y1"]*s, shape[i]["x2"]*s, shape[i]["y2"]*s, shape[i]["x3"]*s, shape[i]["y3"]*s)
    ElseIf shape[i]["func"] = "line" Then
      shape[i]["obj"] = Shapes.AddLine(shape[i]["x1"]*s, shape[i]["y1"]*s, shape[i]["x2"]*s, shape[i]["y2"]*s)
    EndIf
    Shapes.Move(shape[i]["obj"], shX + shape[i]["x"]*s, shY + shape[i]["y"]*s)
    Shapes.Rotate(shape[i]["obj"], shape[i]["angle"])
  EndFor
EndSub

Sub Crab_enter
  cdx=shx+shape[3]["x"]-shape[21]["x"]+shape[3]["width"]/2
  cdY=shy+shape[3]["y"]-shape[21]["height"]*s+12
  For k=start To end
    Shapes.Move(shape[k]["obj"],Shapes.GetLeft(shape[k]["obj"])+cdx,Shapes.Gettop(shape[k]["obj"])+cdy)
  EndFor
EndSub

Sub Shapes_Init
  GraphicsWindow.Title=" Water Clock "
  GraphicsWindow.Hide()
  GraphicsWindow.BackgroundColor="Darkgreen"
  GraphicsWindow.Width=480
  GraphicsWindow.Height=380
  shX = 70                    ' x offset
  shY = 50                    ' y offset
  s=1
  shape[1] = "func=rect;x=309;y=42;width=41;height=80;bc=#FFFFF7;pc=#000000;pw=2;"
  shape[2] = "func=rect;x=204;y=123;width=108;height=80;bc=#FFFFF7;pc=#000000;pw=2;"
  shape[3] = "func=rect;x=33;y=205;width=170;height=96;bc=#FFFFF7;pc=#000000;pw=2;"
  shape[4] = "func=rect;x=274;y=81;width=35;height=10;bc=#263631;pc=#000000;pw=2;"
  shape[5] = "func=tri;x=283;y=75;x1=6;y1=0;x2=0;y2=18;x3=12;y3=18;angle=181;bc=#FF0004;pc=#000000;pw=2;"
  shape[6] = "func=rect;x=170;y=163;width=35;height=10;bc=#263631;pc=#000000;pw=2;"
  shape[7] = "func=tri;x=176;y=157;x1=6;y1=0;x2=0;y2=18;x3=12;y3=18;angle=181;bc=#FF0004;pc=#000000;pw=2;"
  shape[8] = "func=rect;x=0;y=248;width=35;height=10;bc=#263631;pc=#000000;pw=2;"
  shape[9] = "func=tri;x=5;y=244;x1=6;y1=0;x2=0;y2=18;x3=12;y3=18;angle=181;bc=#FF0004;pc=#000000;pw=2;"
  shape[10] = "func=rect;x=338;y=10;width=45;height=9;bc=#00AFB1;pc=#000000;pw=2;"
  shape[11] = "func=rect;x=332;y=12;width=9;height=17;angle=9;bc=#00AFB1;pc=#000000;pw=2;"
  shape[12] = "func=rect;x=355;y=0;width=9;height=17;bc=#00AFB1;pc=#000000;pw=2;"
  shape[13] = "func=rect;x=350;y=-5;width=19;height=7;bc=#00AFB1;pc=#000000;pw=2;"
  shape[14] = "func=ell;x=351;y=5;width=18;height=19;bc=#00AFB1;pc=#000000;pw=2;"
  shape[15] = "func=rect;x=309;y=42;width=41;height=80;bc=#00CED1;pc=#0000CD;pw=2;"
  shape[16] = "func=rect;x=204;y=123;width=108;height=80;bc=#00CED1;pc=#0000CD;pw=2;"
  shape[17] = "func=rect;x=33;y=205;width=170;height=96;bc=#00CED1;pc=#0000CD;pw=2;"
  start=1
  end=Array.GetItemCount(shape)
EndSub

Sub Shapes_Crab
  s=0.15
  shape[21] = "func=rect;x=109;y=173;width=138;height=81;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[22] = "func=ell;x=96;y=173;width=26;height=80;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[23] = "func=ell;x=233;y=174;width=26;height=80;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[24] = "func=rect;x=253;y=172;width=58;height=14;angle=341;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[25] = "func=tri;x=341;y=130;x1=6;y1=0;x2=0;y2=87;x3=13;y3=87;angle=95;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[26] = "func=rect;x=257;y=197;width=58;height=14;angle=356;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[27] = "func=tri;x=340;y=179;x1=7;y1=0;x2=0;y2=76;x3=14;y3=76;angle=113;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[28] = "func=rect;x=256;y=219;width=48;height=16;angle=1;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[29] = "func=tri;x=317;y=210;x1=7;y1=0;x2=0;y2=53;x3=14;y3=53;angle=113;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[30] = "func=rect;x=252;y=246;width=43;height=13;angle=15;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[31] = "func=tri;x=302;y=247;x1=6;y1=0;x2=0;y2=43;x3=12;y3=43;angle=124;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[32] = "func=rect;x=215;y=150;width=7;height=25;bc=#FF0000;pc=#FF0000;pw=2;"
  shape[33] = "func=rect;x=226;y=148;width=8;height=0;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[34] = "func=ell;x=205;y=135;width=20;height=25;bc=#FF0000;pc=#FF0000;pw=2;"
  shape[35] = "func=rect;x=135;y=150;width=7;height=25;bc=#FF0000;pc=#FF0000;pw=2;"
  shape[36] = "func=ell;x=125;y=131;width=20;height=25;bc=#FF0000;pc=#FF0000;pw=2;"
  shape[37] = "func=rect;x=241;y=149;width=72;height=14;angle=321;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[38] = "func=ell;x=194;y=73;width=137;height=61;angle=25;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[39] = "func=tri;x=231;y=85;x1=8;y1=0;x2=0;y2=14;x3=16;y3=14;angle=31;bc=#FFFFFF;pc=#B55D1D;pw=2;"
  shape[40] = "func=tri;x=216;y=77;x1=8;y1=0;x2=0;y2=14;x3=16;y3=14;angle=25;bc=#FFFFFF;pc=#B55D1D;pw=2;"
  shape[41] = "func=tri;x=262;y=98;x1=8;y1=0;x2=0;y2=14;x3=16;y3=14;angle=26;bc=#FFFFFF;pc=#B55D1D;pw=2;"
  shape[42] = "func=tri;x=276;y=106;x1=8;y1=0;x2=0;y2=14;x3=16;y3=14;angle=28;bc=#FFFFFF;pc=#B55D1D;pw=2;"
  shape[43] = "func=tri;x=291;y=112;x1=8;y1=0;x2=0;y2=14;x3=16;y3=14;angle=22;bc=#FFFFFF;pc=#B55D1D;pw=2;"
  shape[44] = "func=tri;x=247;y=92;x1=8;y1=0;x2=0;y2=14;x3=16;y3=14;angle=31;bc=#FFFFFF;pc=#B55D1D;pw=2;"
  shape[45] = "func=rect;x=64;y=247;width=43;height=13;angle=339;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[46] = "func=tri;x=43;y=250;x1=6;y1=0;x2=0;y2=43;x3=12;y3=43;angle=236;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[47] = "func=rect;x=49;y=223;width=48;height=16;angle=348;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[48] = "func=tri;x=19;y=216;x1=6;y1=0;x2=0;y2=55;x3=13;y3=55;angle=250;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[49] = "func=rect;x=39;y=200;width=58;height=14;angle=357;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[50] = "func=tri;x=2;y=187;x1=6;y1=0;x2=0;y2=79;x3=12;y3=79;angle=243;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[51] = "func=rect;x=43;y=179;width=58;height=14;angle=6;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[52] = "func=tri;x=0;y=153;x1=6;y1=0;x2=0;y2=89;x3=13;y3=89;angle=249;bc=#B5451D;pc=#B55D1D;pw=2;"
  shape[53] = "func=rect;x=41;y=150;width=69;height=15;angle=37;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[54] = "func=ell;x=42;y=100;width=83;height=34;angle=140;bc=#B55D1D;pc=#B55D1D;pw=2;"
  shape[55] = "func=line;x=99;y=98;x1=6;y1=0;x2=0;y2=15;pc=#FFFFFF;pw=2;"
  shape[56] = "func=line;x=82;y=112;x1=19;y1=0;x2=0;y2=2;pc=#FFFFFF;pw=2;"
  shape[57] = "func=line;x=83;y=113;x1=0;y1=0;x2=0;y2=18;pc=#FFFFFF;pw=2;"
  shape[58] = "func=line;x=62;y=130;x1=0;y1=5;x2=20;y2=0;pc=#FFFFFF;pw=2;"
  shape[59] = "func=line;x=158;y=43;x1=0;y1=0;x2=1;y2=0;pc=#FFFFFF;pw=2;"
  shape[60] = "func=line;x=126;y=192;x1=0;y1=0;x2=15;y2=12;pc=#B5451D;pw=2;"
  shape[61] = "func=line;x=139;y=205;x1=0;y1=0;x2=2;y2=15;pc=#B5451D;pw=2;"
  shape[62] = "func=line;x=127;y=217;x1=14;y1=0;x2=0;y2=18;pc=#B5451D;pw=2;"
  shape[63] = "func=line;x=210;y=192;x1=14;y1=0;x2=0;y2=9;pc=#B5451D;pw=2;"
  shape[64] = "func=line;x=209;y=202;x1=0;y1=0;x2=0;y2=18;pc=#B5451D;pw=2;"
  shape[65] = "func=line;x=210;y=221;x1=0;y1=0;x2=8;y2=11;pc=#B5451D;pw=2;"
  cddx=-1
  cddy=-1
  start=21
  end=Array.GetItemCount(shape)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.