Microsoft Small Basic

Program Listing:
Embed this in your website
' Happy Birthday Small Basic!!
' Copyright © 2014-2017 Nonki Takahashi. The MIT License.
' 2014-10-23 20:26:31 Shapes generated by Shapes 1.7b.
' Program ID SFF730-1
'
SB_Workaround()
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "The 9th Anniversary"
' fill background
Colors_Init()
param = "x=0;y=0;width=" + gw + ";height=" + gh + ";angle=70;"
param = param + "0=" + colors["Blue"] + ";70=" + colors["RoyalBlue"] + ";100=" + colors["Azure"] + ";"
FillLinearGradientRectangle()
' draw Happy Birthday Small Basic!!
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.FontSize = 500
GraphicsWindow.BrushColor = "#33000000"
x = 280
y = -70
GraphicsWindow.DrawText(x, y, "9")
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.FontSize = 32
GraphicsWindow.FontBold = "False"
GraphicsWindow.BrushColor = "White"
x = (gw - 469) / 2
y = 60
GraphicsWindow.DrawText(x, y, "Happy 9th Birthday Small Basic!!")
' initialize shapes
Shapes_Init()
' add shapes
scale = 1
angle = 0
iMin = 1
iMax = 35
Shapes_Add()
' ticker tape animation
GraphicsWindow.PenWidth = 0
nMin = 1
nMax = 0
AddTickerTape()
Timer.Interval = 1000 / 24
Timer.Tick = OnTick
' happy birthday song
For b = 1 To 9
  BirthdaySong()
EndFor

Sub BirthdaySong
  Sound.PlayMusic("O4C6C12D4C4F4E2")
  Sound.PlayMusic("C6C12D4C4G4F2")
  Sound.PlayMusic("C6C12O5C4O4A4F6F12E4D4")
  Sound.PlayMusic("B-6B-12A4F4G4F2")
EndSub

Sub AddTickerTape
  nMax = nMax + 1
  GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
  tt[nMax] = Shapes.AddRectangle(16, 8)
  x[nMax] = Math.GetRandomNumber(gw - 20) + 10
  y[nMax] = -10
  a[nMax] = Math.GetRandomNumber(360) - 1
  Shapes.Rotate(tt[nMax], a[nMax])
  Shapes.Move(tt[nMax], x[nMax], y[nMax])
EndSub

Sub OnTick
    If Math.GetRandomNumber(10) = 1 Then
      AddTickerTape()
    EndIf
    For i = nMin To nMax
      x[i] = x[i] + Math.GetRandomNumber(4) - 2
      y[i] = y[i] + Math.GetRandomNumber(4)
      If y[i] > gh + 60 Then
        Shapes.Remove(tt[i])
        nMin = i + 1
      EndIf
      Shapes.Move(tt[i], x[i], y[i])
      a[i] = a[i] + 45
      If a[i] >= 360 Then
        a[i] = a[i] - 360
      EndIf
      Shapes.Zoom(tt[i], 1, Math.Sin(Math.GetRadians(a[i])))
    EndFor
EndSub

Sub Shapes_Init
  ' Shapes | Initialize shapes data
  ' return shX, shY - current position of shapes
  ' return shape - array of shapes
  shX = 180 ' x offset
  shY = 140 ' y offset
  shape = ""
  shape[1] = "func=ell;x=0;y=180;width=200;height=50;bc=#D6D6D6;pw=0;"
  shape[2] = "func=rect;x=0;y=155;width=200;height=51;bc=#D6D6D6;pw=0;"
  shape[3] = "func=ell;x=0;y=128;width=200;height=50;bc=#FFFFFF;pw=0;"
  shape[4] = "func=ell;x=25;y=139;width=154;height=28;bc=#D6D6D6;pw=0;"
  shape[5] = "func=rect;x=25;y=106;width=154;height=48;bc=#D6D6D6;pw=0;"
  shape[6] = "func=ell;x=25;y=94;width=154;height=28;bc=#FFFFFF;pw=0;"
  shape[7] = "func=ell;x=49;y=101;width=105;height=14;bc=#D6D6D6;pw=0;"
  shape[8] = "func=rect;x=49;y=63;width=105;height=45;bc=#D6D6D6;pw=0;"
  shape[9] = "func=ell;x=49;y=57;width=105;height=14;bc=#FFFFFF;pw=0;"
  shape[10] = "func=ell;x=94;y=61;width=14;height=5;bc=#ED933A;pw=0;"
  shape[11] = "func=rect;x=96;y=8;width=10;height=55;bc=#ED933A;pw=0;"
  shape[12] = "func=tri;x=96;y=0;x1=5;y1=0;x2=0;y2=10;x3=10;y3=10;bc=#ED933A;pw=0;"
  shape[13] = "func=tri;x=71;y=2;x1=5;y1=0;x2=0;y2=10;x3=10;y3=10;bc=#8BED3A;pw=0;"
  shape[14] = "func=tri;x=121;y=1;x1=5;y1=0;x2=0;y2=10;x3=10;y3=10;bc=#3AB7ED;pw=0;"
  shape[15] = "func=rect;x=121;y=8;width=10;height=55;bc=#3AB7ED;pw=0;"
  shape[16] = "func=rect;x=71;y=10;width=10;height=55;bc=#8BED3A;pw=0;"
  shape[17] = "func=ell;x=119;y=61;width=14;height=5;bc=#3AB7ED;pw=0;"
  shape[18] = "func=ell;x=69;y=61;width=14;height=5;bc=#8BED3A;pw=0;"
  shape[19] = "func=ell;x=35;y=99;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[20] = "func=ell;x=53;y=103;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[21] = "func=ell;x=71;y=105;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[22] = "func=ell;x=90;y=106;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[23] = "func=ell;x=109;y=106;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[24] = "func=ell;x=130;y=104;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[25] = "func=ell;x=152;y=99;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[26] = "func=ell;x=11;y=141;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[27] = "func=ell;x=24;y=149;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[28] = "func=ell;x=42;y=154;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[29] = "func=ell;x=65;y=158;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[30] = "func=ell;x=87;y=160;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[31] = "func=ell;x=108;y=160;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[32] = "func=ell;x=131;y=159;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[33] = "func=ell;x=149;y=155;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[34] = "func=ell;x=167;y=150;width=13;height=14;bc=#ED3A3A;pw=0;"
  shape[35] = "func=ell;x=180;y=140;width=13;height=14;bc=#ED3A3A;pw=0;"
EndSub

Sub Math_CartesianToPolar
  ' Math | convert cartesian coodinate to polar coordinate
  ' param x, y - cartesian coordinate
  ' return r, a - polar coordinate
  r = Math.SquareRoot(x * x + y * y)
  If x = 0 And y > 0 Then
    a = 90 ' [degree]
  ElseIf x = 0 And y < 0 Then
    a = -90
  Else
    a = Math.ArcTan(y / x) * 180 / Math.Pi
  EndIf
  If x < 0 Then
    a = a + 180
  ElseIf x > 0 And y < 0 Then
    a = a + 360
  EndIf
EndSub

Sub SB_RotateWorkaround
  ' Small Basic | Rotate workaround for Silverlight
  ' param x, y - original coordinate
  ' param alpha - angle [radian]
  ' returns x, y - workaround coordinate
  If shape[i]["func"] = "tri" Then
    x1 = -Math.Floor(shape[i]["x3"] / 2)
    y1 = -Math.Floor(shape[i]["y3"] / 2)
  ElseIf shape[i]["func"] = "line" Then
    x1 = -Math.Floor(Math.Abs(shape[i]["x1"] - shape[i]["x2"]) / 2)
    y1 = -Math.Floor(Math.Abs(shape[i]["y1"] - shape[i]["y2"]) / 2)
  EndIf
  ox = x - x1
  oy = y - y1
  x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
  y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
EndSub

Sub SB_Workaround
  ' Small Basic | Workaround for Silverlight
  ' returns silverlight - "True" if in remote
  color = GraphicsWindow.GetPixel(0, 0)
  If Text.GetLength(color) > 7 Then
    silverlight = "True"
    msWait = 300
  Else
    silverlight = "False"
  EndIf
EndSub

Sub Shapes_Add
  ' Shapes | add shapes as shapes data
  ' param iMin, iMax - shape indices to add
  ' param shape - array of shapes
  ' param scale - 1 if same scale
  ' return shWidth, shHeight - total size of shapes
  ' return shAngle - current angle of shapes
  Stack.PushValue("local", i)
  Stack.PushValue("local", x)
  Stack.PushValue("local", y)
  Shapes_CalcWidthAndHeight()
  s = scale
  For i = iMin To iMax
    GraphicsWindow.PenWidth = shape[i]["pw"] * s
    If shape[i]["pw"] > 0 Then
      GraphicsWindow.PenColor = shape[i]["pc"]
    EndIf
    If Text.IsSubText("rect|ell|tri|text", shape[i]["func"]) Then
      GraphicsWindow.BrushColor = shape[i]["bc"]
    EndIf
    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)
    ElseIf shape[i]["func"] = "text" Then
      If silverlight Then
        fs = Math.Floor(shape[i]["fs"] * 0.9)
      Else
        fs = shape[i]["fs"]
      EndIf
      GraphicsWindow.FontSize = fs * s
      GraphicsWindow.FontName = shape[i]["fn"]
      shape[i]["obj"] = Shapes.AddText(shape[i]["text"])
    EndIf
    x = shape[i]["x"]
    y = shape[i]["y"]
    shape[i]["rx"] = x
    shape[i]["ry"] = y
    If silverlight And Text.IsSubText("tri|line", shape[i]["func"]) Then
      alpha = Math.GetRadians(shape[i]["angle"])
      SB_RotateWorkaround()
      shape[i]["wx"] = x
      shape[i]["wy"] = y
    EndIf
    Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    If Text.IsSubText("rect|ell|tri|text", shape[i]["func"]) And shape[i]["angle"] <> 0 Then
      Shapes.Rotate(shape[i]["obj"], shape[i]["angle"])
    EndIf
  EndFor
  shAngle = 0
  y = Stack.PopValue("local")
  x = Stack.PopValue("local")
  i = Stack.PopValue("local")
EndSub

Sub Shapes_CalcRotatePos
  ' Shapes | Calculate position for rotated shape
  ' param["x"], param["y"] - position of a shape
  ' param["width"], param["height"] - size of a shape
  ' param ["cx"], param["cy"] - center of rotation
  ' param ["angle"] - rotate angle
  ' return x, y - rotated position of a shape
  _cx = param["x"] + param["width"] / 2
  _cy = param["y"] + param["height"] / 2
  x = _cx - param["cx"]
  y = _cy - param["cy"]
  Math_CartesianToPolar()
  a = a + param["angle"]
  x = r * Math.Cos(a * Math.Pi / 180)
  y = r * Math.Sin(a * Math.Pi / 180)
  _cx = x + param["cx"]
  _cy = y + param["cy"]
  x = _cx - param["width"] / 2
  y = _cy - param["height"] / 2
EndSub

Sub Shapes_CalcWidthAndHeight
  ' Shapes | Calculate total width and height of shapes
  ' param iMin, iMax - shape indices to add
  ' return shWidth, shHeight - total size of shapes
  For i = iMin To iMax
    If shape[i]["func"] = "tri" Or shape[i]["func"] = "line" Then
      xmin = shape[i]["x1"]
      xmax = shape[i]["x1"]
      ymin = shape[i]["y1"]
      ymax = shape[i]["y1"]
      If shape[i]["x2"] < xmin Then
        xmin = shape[i]["x2"]
      EndIf
      If xmax < shape[i]["x2"] Then
        xmax = shape[i]["x2"]
      EndIf
      If shape[i]["y2"] < ymin Then
        ymin = shape[i]["y2"]
      EndIf
      If ymax < shape[i]["y2"] Then
        ymax = shape[i]["y2"]
      EndIf
      If shape[i]["func"] = "tri" Then
        If shape[i]["x3"] < xmin Then
          xmin = shape[i]["x3"]
        EndIf
        If xmax < shape[i]["x3"] Then
          xmax = shape[i]["x3"]
        EndIf
        If shape[i]["y3"] < ymin Then
          ymin = shape[i]["y3"]
        EndIf
        If ymax < shape[i]["y3"] Then
          ymax = shape[i]["y3"]
        EndIf
      EndIf
      shape[i]["width"] = xmax - xmin
      shape[i]["height"] = ymax - ymin
    EndIf
    If i = 1 Then
      shWidth = shape[i]["x"] + shape[i]["width"]
      shHeight = shape[i]["y"] + shape[i]["height"]
    Else
      If shWidth < shape[i]["x"] + shape[i]["width"] Then
        shWidth = shape[i]["x"] + shape[i]["width"]
      EndIf
      If shHeight < shape[i]["y"] + shape[i]["height"] Then
        shHeight = shape[i]["y"] + shape[i]["height"]
      EndIf
    EndIf
  EndFor
EndSub

Sub Shapes_Move
  ' Shapes | Move shapes
  ' param iMin, iMax - shape indices to add
  ' param shape - array of shapes
  ' param scale - to zoom
  ' param x, y - position to move
  ' return shX, shY - new position of shapes
  Stack.PushValue("local", i)
  s = scale
  shX = x
  shY = y
  For i = iMin To iMax
    If silverlight And Text.IsSubText("tri|line", shape[i]["func"]) Then
      _x = shape[i]["wx"]
      _y = shape[i]["wy"]
    Else
      _x = shape[i]["rx"]
      _y = shape[i]["ry"]
    EndIf
    Shapes.Move(shape[i]["obj"], shX + _x * s, shY + _y * s)
  EndFor
  i = Stack.PopValue("local")
EndSub

Sub Shapes_Remove
  ' Shapes | Remove shapes
  ' param iMin, iMax - shapes indices to remove
  ' param shape - array of shapes
  Stack.PushValue("local", i)
  For i = iMin To iMax
    Shapes.Remove(shape[i]["obj"])
  EndFor
  i = Stack.PopValue("local")
EndSub

Sub Shapes_Rotate
  ' Shapes | Rotate shapes
  ' param iMin, iMax - shapes indices to rotate
  ' param shape - array of shapes
  ' param scale - to zoom
  ' param angle - to rotate
  Stack.PushValue("local", i)
  Stack.PushValue("local", x)
  Stack.PushValue("local", y)
  s = scale
  param["angle"] = angle
  param["cx"] = shWidth / 2
  param["cy"] = shHeight / 2
  For i = iMin To iMax
    param["x"] = shape[i]["x"]
    param["y"] = shape[i]["y"]
    param["width"] = shape[i]["width"]
    param["height"] = shape[i]["height"]
    Shapes_CalcRotatePos()
    shape[i]["rx"] = x
    shape[i]["ry"] = y
    If silverlight And Text.IsSubText("tri|line", shape[i]["func"]) Then
      alpha = Math.GetRadians(angle + shape[i]["angle"])
      SB_RotateWorkAround()
      shape[i]["wx"] = x
      shape[i]["wy"] = y
    EndIf
    Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
    Shapes.Rotate(shape[i]["obj"], angle + shape[i]["angle"])
  EndFor
  y = Stack.PopValue("local")
  x = Stack.PopValue("local")
  i = Stack.PopValue("local")
EndSub

Sub FillLinearGradientRectangle
  ' param["x"], param["y"] - position of the rectangle
  ' param["width"], param["height"] - size of the rectangle
  ' param["angle"] - angle of gradient
  ' param["0"]..param["100"] - 0% to 100% colors
  x0 = param["x"]
  y0 = param["y"]
  width = param["width"]
  height = param["height"]
  angle = param["angle"]
  n = Array.GetItemCount(param)
  index = Array.GetAllIndices(param)
  color = ""
  For i = 1 To n
    If index[i] + 0 = index[i] And 0 <= index[i] And index[i] <= 100 Then
      color[index[i]] = param[index[i]]
    EndIf
  EndFor
  If color[0] = "" Then
    color[0] = GraphicsWindow.BrushColor
  EndIf
  If color[100] = "" Then
    color[100] = GraphicsWindow.BrushColor
  EndIf
  n = Array.GetItemCount(color)
  index = Array.GetAllIndices(color)
  a45 = Math.Remainder(angle, 45)
  If 0 <= angle And angle < 45 Then
    w45 = width
    h45 = height
  ElseIf 45 <= angle And angle < 90 Then
    w45 = height
    h45 = width
    a45 = 45 - a45
  ElseIf 90 <= angle And angle < 135 Then
    w45 = height
    h45 = width
  ElseIf 135 <= angle And angle < 180 Then
    w45 = width
    h45 = height
    a45 = 45 - a45
  ElseIf 180 <= angle And angle < 225 Then
    w45 = width
    h45 = height
  ElseIf 225 <= angle And angle < 270 Then
    w45 = height
    h45 = width
    a45 = 45 - a45
  ElseIf 270 <= angle And angle < 315 Then
    w45 = height
    h45 = width
  ElseIf 315 <= angle And angle < 360 Then
    w45 = width
    h45 = height
    a45 = 45 - a45
  EndIf
  If a45 = 0 Then
    For x = 0 To w45
      percent = Math.Floor(x * 100 / w45)
      Color_PercentToRGB()
      x1 = x
      y1 = 0
      x2 = x
      y2 = h45
      DrawLine()
    EndFor
  ElseIf 0 < a45 And a45 <= 45 Then
    tan = Math.Tan(Math.GetRadians(a45))
    If h45 <= w45 Then
      dx = Math.Floor(h45 * tan)
      For x = 0 To dx
        percent = Math.Floor(x * 100 / (w45 + dx))
        Color_PercentToRGB()
        x1 = x
        y1 = 0
        x2 = 0
        y2 = Math.Floor(x / tan)
        DrawLine()
      EndFor
      For x = dx To w45
        percent = Math.Floor(x * 100 / (w45 + dx))
        Color_PercentToRGB()
        x1 = x
        y1 = 0
        x2 = x - dx
        y2 = h45
        DrawLine()
      EndFor
      For x = w45 To w45 + dx
        percent = Math.Floor(x * 100 / (w45 + dx))
        Color_PercentToRGB()
        x1 = x - dx
        y1 = h45
        x2 = w45
        y2 = Math.Floor((x - w45) / tan)
        DrawLine()
      EndFor
    Else  ' width < height
      dx = Math.Floor(h45 * tan - w45)
      dy = Math.Floor(w45 / tan)
      For x = 0 To w45
        percent = Math.Floor(x * 100 / (2 * w45 + dx))
        Color_PercentToRGB()
        x1 = x
        y1 = 0
        x2 = 0
        y2 = Math.Floor(x / tan)
        DrawLine()
      EndFor
      For x = 0 To dx
        percent = Math.Floor((x + w45) * 100 / (2 * w45 + dx))
        Color_PercentToRGB()
        x1 = w45
        y1 = Math.Floor(x / tan)
        x2 = 0
        y2 = y1 + dy
        DrawLine()
      EndFor
      dy = h45 - Math.Floor(w45 / tan)
      For x = 0 To w45
        percent = Math.Floor((x + w45 + dx) * 100 / (2 * w45 + dx))
        Color_PercentToRGB()
        x1 = x
        y1 = h45
        x2 = w45
        y2 = dy + Math.Floor(x / tan)
        DrawLine()
      EndFor
    EndIf
  EndIf
EndSub

Sub DrawLine
  ' param r, g, b - red, green blue
  ' param angle
  ' param x1, y1, x2, y2 - edges of line
  GraphicsWindow.PenColor = GraphicsWindow.GetColorFromRGB(r, g, b)
  If 0 <= angle And angle < 45 Then
    GraphicsWindow.DrawLine(x1 + x0, y1 + y0, x2 + x0, y2 + y0)
  ElseIf 45 <= angle And angle < 90 Then
    GraphicsWindow.DrawLine(y1 + x0, x1 + y0, y2 + x0, x2 + y0)
  ElseIf 90 <= angle And angle < 135 Then
    GraphicsWindow.DrawLine(-y1 + x0 + width, x1 + y0, -y2 + x0 + width, x2 + y0)
  ElseIf 135 <= angle And angle < 180 Then
    GraphicsWindow.DrawLine(-x1 + x0 + width, y1 + y0, -x2 + x0 + width, y2 + y0)
  ElseIf 180 <= angle And angle < 225 Then
    GraphicsWindow.DrawLine(-x1 + x0 + width, -y1 + y0 + height, -x2 + x0 + width, -y2 + y0 + height)
  ElseIf 225 <= angle And angle < 270 Then
    GraphicsWindow.DrawLine(-y1 + x0 + width, -x1 + y0 + height, -y2 + x0 + width, -x2 + y0 + height)
  ElseIf 270 <= angle And angle < 315 Then
    GraphicsWindow.DrawLine(y1 + x0, -x1 + y0 + height, y2 + x0, -x2 + y0 + height)
  ElseIf 315 <= angle And angle < 360 Then
    GraphicsWindow.DrawLine(x1 + x0, -y1 + y0 + height, x2 + x0, -y2 + y0 + height)
  EndIf
EndSub

Sub Color_PercentToRGB
  ' Color | Convert Percent to RGB
  ' param percent - percent
  ' param color[] - color table indexed percent
  ' param n - item count of color[]
  ' param index[] - all indices of color[]
  For i = 1 To n
    p1 = index[i]
    If index[i] = percent Then
      p2 = index[i]
      i = n + 1 ' break
    ElseIf index[i] < percent And percent < index[i + 1] Then
      p2 = index[i + 1]
      i = n + 1 ' break
    EndIf
  EndFor
  c = color[p1]
  Color_ColorToRGB()
  If p1 <> p2 Then
    r1 = r
    g1 = g
    b1 = b
    c = color[p2]
    Color_ColorToRGB()
    r2 = r
    g2 = g
    b2 = b
    r = Math.Floor(r1 + (r2 - r1) * (percent - p1) / (p2 - p1))
    g = Math.Floor(g1 + (g2 - g1) * (percent - p1) / (p2 - p1))
    b = Math.Floor(b1 + (b2 - b1) * (percent - p1) / (p2 - p1))
  EndIf
EndSub

Sub Color_ColorToRGB
  ' Color | Convert Color to RGB
  ' param c - color
  ' returns r, g, b - red, green and blue values
  If Text.StartsWith(c, "#") Then
    c = Text.ConvertToUpperCase(c)
  Else
    c = Text.ConvertToLowerCase(c)
    c = colors[c]
  EndIf
  sHex = Text.GetSubText(c, 2, 2)
  Math_Hex2Dec()
  r = iDec
  sHex = Text.GetSubText(c, 4, 2)
  Math_Hex2Dec()
  g = iDec
  sHex = Text.GetSubText(c, 6, 2)
  Math_Hex2Dec()
  b = iDec
EndSub

Sub Math_Hex2Dec
  ' Math | Convert hexadecimal to decimal
  ' param sHex
  ' returns iDec
  iDec = 0
  iLen = Text.GetLength(sHex)
  For iPtr = 1 To iLen
    iDec = iDec * 16 + Text.GetIndexOf("0123456789ABCDEF", Text.GetSubText(sHex, iPtr, 1)) - 1
  EndFor
EndSub

Sub Colors_Init
  colors["aliceblue"]="#F0F8FF"
  colors["antiquewhite"]="#FAEBD7"
  colors["aqua"]="#00FFFF"
  colors["aquamarine"]="#7FFFD4"
  colors["azure"]="#F0FFFF"
  colors["beige"]="#F5F5DC"
  colors["bisque"]="#FFE4C4"
  colors["black"]="#000000"
  colors["blanchedalmond"]="#FFEBCD"
  colors["blue"]="#0000FF"
  colors["blueviolet"]="#8A2BE2"
  colors["brown"]="#A52A2A"
  colors["burlywood"]="#DEB887"
  colors["cadetblue"]="#5F9EA0"
  colors["chartreuse"]="#7FFF00"
  colors["chocolate"]="#D2691E"
  colors["coral"]="#FF7F50"
  colors["cornflowerblue"]="#6495ED"
  colors["cornsilk"]="#FFF8DC"
  colors["crimson"]="#DC143C"
  colors["cyan"]="#00FFFF"
  colors["darkblue"]="#00008B"
  colors["darkcyan"]="#008B8B"
  colors["darkgoldenrod"]="#B8860B"
  colors["darkgray"]="#A9A9A9"
  colors["darkgreen"]="#006400"
  colors["darkkhaki"]="#BDB76B"
  colors["darkmagenta"]="#8B008B"
  colors["darkolivegreen"]="#556B2F"
  colors["darkorange"]="#FF8C00"
  colors["darkorchid"]="#9932CC"
  colors["darkred"]="#8B0000"
  colors["darksalmon"]="#E9967A"
  colors["darkseagreen"]="#8FBC8F"
  colors["darkslateblue"]="#483D8B"
  colors["darkslategray"]="#2F4F4F"
  colors["darkturquoise"]="#00CED1"
  colors["darkviolet"]="#9400D3"
  colors["deeppink"]="#FF1493"
  colors["deepskyblue"]="#00BFFF"
  colors["dimgray"]="#696969"
  colors["dodgerblue"]="#1E90FF"
  colors["firebrick"]="#B22222"
  colors["floralwhite"]="#FFFAF0"
  colors["forestgreen"]="#228B22"
  colors["fuchsia"]="#FF00FF"
  colors["gainsboro"]="#DCDCDC"
  colors["ghostwhite"]="#F8F8FF"
  colors["gold"]="#FFD700"
  colors["goldenrod"]="#DAA520"
  colors["gray"]="#808080"
  colors["green"]="#008000"
  colors["greenyellow"]="#ADFF2F"
  colors["honeydew"]="#F0FFF0"
  colors["hotpink"]="#FF69B4"
  colors["indianred"]="#CD5C5C"
  colors["indigo"]="#4B0082"
  colors["ivory"]="#FFFFF0"
  colors["khaki"]="#F0E68C"
  colors["lavender"]="#E6E6FA"
  colors["lavenderblush"]="#FFF0F5"
  colors["lawngreen"]="#7CFC00"
  colors["lemonchiffon"]="#FFFACD"
  colors["lightblue"]="#ADD8E6"
  colors["lightcoral"]="#F08080"
  colors["lightcyan"]="#E0FFFF"
  colors["lightgoldenrodyellow"]="#FAFAD2"
  colors["lightgray"]="#D3D3D3"
  colors["lightgreen"]="#90EE90"
  colors["lightpink"]="#FFB6C1"
  colors["lightsalmon"]="#FFA07A"
  colors["lightseagreen"]="#20B2AA"
  colors["lightskyblue"]="#87CEFA"
  colors["lightslategray"]="#778899"
  colors["lightsteelblue"]="#B0C4DE"
  colors["lightyellow"]="#FFFFE0"
  colors["lime"]="#00FF00"
  colors["limegreen"]="#32CD32"
  colors["linen"]="#FAF0E6"
  colors["magenta"]="#FF00FF"
  colors["maroon"]="#800000"
  colors["mediumaquamarine"]="#66CDAA"
  colors["mediumblue"]="#0000CD"
  colors["mediumorchid"]="#BA55D3"
  colors["mediumpurple"]="#9370DB"
  colors["mediumseagreen"]="#3CB371"
  colors["mediumslateblue"]="#7B68EE"
  colors["mediumspringgreen"]="#00FA9A"
  colors["mediumturquoise"]="#48D1CC"
  colors["mediumvioletred"]="#C71585"
  colors["midnightblue"]="#191970"
  colors["mintcream"]="#F5FFFA"
  colors["mistyrose"]="#FFE4E1"
  colors["moccasin"]="#FFE4B5"
  colors["navajowhite"]="#FFDEAD"
  colors["navy"]="#000080"
  colors["oldlace"]="#FDF5E6"
  colors["olive"]="#808000"
  colors["olivedrab"]="#6B8E23"
  colors["orange"]="#FFA500"
  colors["orangered"]="#FF4500"
  colors["orchid"]="#DA70D6"
  colors["palegoldenrod"]="#EEE8AA"
  colors["palegreen"]="#98FB98"
  colors["paleturquoise"]="#AFEEEE"
  colors["palevioletred"]="#DB7093"
  colors["papayawhip"]="#FFEFD5"
  colors["peachpuff"]="#FFDAB9"
  colors["peru"]="#CD853F"
  colors["pink"]="#FFC0CB"
  colors["plum"]="#DDA0DD"
  colors["powderblue"]="#B0E0E6"
  colors["purple"]="#800080"
  colors["red"]="#FF0000"
  colors["rosybrown"]="#BC8F8F"
  colors["royalblue"]="#4169E1"
  colors["saddlebrown"]="#8B4513"
  colors["salmon"]="#FA8072"
  colors["sandybrown"]="#F4A460"
  colors["seagreen"]="#2E8B57"
  colors["seashell"]="#FFF5EE"
  colors["sienna"]="#A0522D"
  colors["silver"]="#C0C0C0"
  colors["skyblue"]="#87CEEB"
  colors["slateblue"]="#6A5ACD"
  colors["slategray"]="#708090"
  colors["snow"]="#FFFAFA"
  colors["springgreen"]="#00FF7F"
  colors["steelblue"]="#4682B4"
  colors["tan"]="#D2B48C"
  colors["teal"]="#008080"
  colors["thistle"]="#D8BFD8"
  colors["tomato"]="#FF6347"
  colors["turquoise"]="#40E0D0"
  colors["violet"]="#EE82EE"
  colors["wheat"]="#F5DEB3"
  colors["white"]="#FFFFFF"
  colors["whitesmoke"]="#F5F5F5"
  colors["yellow"]="#FFFF00"
  colors["yellowgreen"]="#9ACD32"
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.