Sub AddSquare
width = param["size"]
x = param["x"]
addColor = param["color"]
For y = param["y"] To param["y"] + width - 1
GetLine()
AddLine()
EndFor
EndSub
Sub GetLine
' param x, y - left end position of the line
' param width - of the line
' return seg - segment array for the line
seg = ""
iSeg = 0
For _x = x To x + width - 1
color = GraphicsWindow.GetPixel(_x, y)
If seg[iSeg]["color"] <> color Then
iSeg = iSeg + 1
seg[iSeg]["color"] = color
seg[iSeg]["x"] = _x
seg[iSeg]["y"] = y
seg[iSeg]["width"] = 1
Else
seg[iSeg]["width"] = seg[iSeg]["width"] + 1
EndIf
EndFor
EndSub
Sub AddLine
' param seg - segment array for a line
' param subColor - color to subtract
nSeg = Array.GetItemCount(seg)
index = Array.GetAllIndices(seg)
color2 = addColor
For iSeg = 1 To nSeg
color1 = seg[iSeg]["color"]
Color_Add()
GraphicsWindow.BrushColor = color
GraphicsWindow.FillRectangle(seg[iSeg]["x"], seg[iSeg]["y"], seg[iSeg]["width"], 1)
EndFor
EndSub
Sub RegularPolygon
For i = 1 To n
a = 2 * Math.Pi * i / n
x3 = x1 + r * Math.Sin(a)
y3 = y1 - r * Math.Cos(a)
GraphicsWindow.FillTriangle(x1, y1, x2, y2, x3, y3) ' fill
'GraphicsWindow.DrawLine(x2, y2, x3, y3) ' draw
x2 = x3
y2 = y3
EndFor
EndSub
Sub Color_Add
' param color1, color2 - for color addition
' return color - result
color = color1
Color_RGBToValues()
rgb1 = rgb
color = color2
Color_RGBToValues()
rgb2 = rgb
For i = 1 To 3
rgb[i] = Math.Min(rgb1[i] + rgb2[i], 255)
EndFor
color = GraphicsWindow.GetColorFromRGB(rgb[1], rgb[2], rgb[3])
EndSub
Sub Color_RGBToValues
' param color - "#rrggbb"
' return rgb[] - 0..255 for each red, green, and blue
hex = Text.GetSubText(color, 2, 2)
Math_Hex2Dec()
rgb[1] = dec
hex = Text.GetSubText(color, 4, 2)
Math_Hex2Dec()
rgb[2] = dec
hex = Text.GetSubText(color, 6, 2)
Math_Hex2Dec()
rgb[3] = dec
EndSub
Sub Math_Hex2Dec
' Math | Convert hexadecimal to decimal
' param hex - hexadecimal
' return dec - decimal
dec = 0
len = Text.GetLength(hex)
For ptr = 1 To len
dec = dec * 16 + Text.GetIndexOf("123456789ABCDEF", Text.GetSubText(hex, ptr, 1))
EndFor
EndSub