Microsoft Small Basic

Program Listing:
Embed this in your website
'Traffic light
Flag = 0
GraphicsWindow.Show()
GraphicsWindow.BackgroundColor  = "Darkgray"
EWH = 100
x = GraphicsWindow.Width / 2 - EWH / 2
y1 = 50
y2 = 160
y3 = 270
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(x-10, y1-10, EWH + 20, y3 + 70)
GraphicsWindow.BrushColor = "Red"
SRed = Shapes.AddEllipse(EWH,EWH)
Shapes.Move(SRed, x, y1)
GraphicsWindow.BrushColor = "Yellow"
SYel = Shapes.AddEllipse(EWH,EWH)
Shapes.Move(SYel, x, y2)
GraphicsWindow.BrushColor = "Green"
SGre = Shapes.AddEllipse(EWH,EWH)
Shapes.Move(SGre, x, y3)
GraphicsWindow.BrushColor = "LigtGray"
SGraRed = Shapes.AddEllipse(EWH,EWH)
Shapes.SetOpacity(SGraRed,70)
SGraYel = Shapes.AddEllipse(EWH,EWH)
Shapes.SetOpacity(SGraYel,80)
SGraGre = Shapes.AddEllipse(EWH,EWH)
Shapes.SetOpacity(SGraGre,70)
Shapes.Move(SGraRed, x, y1)
Shapes.Move(SGraYel, x, y2)
Shapes.Move(SGraGre, x, y3)

Timer.Interval = 100
Timer.Tick = OnTimer

Sub OnTimer
  If Flag = 0 Then
    Timer.Interval = 5000
    Shapes.HideShape(SGraRed)
    Shapes.ShowShape(SGraYel)
    Flag = 1
  ElseIf Flag = 1 Then
    Timer.Interval = 1000
    Shapes.HideShape(SGraYel)
    Flag = 2
  ElseIf Flag = 2 Then
    Timer.Interval = 10000
    Shapes.ShowShape(SGraRed)
    Shapes.ShowShape(SGraYel)
    Shapes.HideShape(SGraGre)
    Flag = 3
  ElseIf Flag = 3 Then
    Timer.Interval = 2000
    Shapes.ShowShape(SGraGre)
    Shapes.HideShape(SGraYel)
    Flag = 0
  EndIf
EndSub


Copyright (c) Microsoft Corporation. All rights reserved.