' average value
a = 10
b = 20
Average()
TextWindow.WriteLine("Average(a=" + a + ", b=" + b + ") = " + c)
' intermediate value
For k = 0 To 1 Step 0.25
Intermediate()
TextWindow.WriteLine("Intermediate(a=" + a + ", b=" + b + ", k=" + k + ") = " + c)
EndFor
TextWindow.WriteLine("")
' intermediate color
For k = 0 To 1 Step 0.25
IntermediateColor()
TextWindow.WriteLine("Intermediate(a=" + colorA + ", b=" + colorB + ", k=" + k + ") = " + colorC)
EndFor
Sub Average
' param a - the first value
' param b - the second value
' return c - the average of the given values
c = (a + b) / 2
EndSub
Sub AveragePoint
' param pointA - the first point
' param pointB - the second point
' return pointC - the average point of the given points
n = Array.GetItemCount(pointA)
index = Array.GetAllIndices(pointA)
For j = 1 To n
a = pointA[index[j]]
b = pointB[index[j]]
Average()
pointC[index[j]] = c
EndFor
EndSub
Sub AverageColor
' param colorA - the first color
' param colorB - the second color
' return colorC - the average of the given colors
For j = 1 To 3
hex = Text.GetSubText(colorA, j * 2, 2)
Hex2Dec()
a = dec
hex = Text.GetSubText(colorB, j * 2, 2)
Hex2Dec()
b = dec
Average()
rgb[j] = c
EndFor
colorC = GraphicsWindow.GetColorFromRGB(rgb[1], rgb[2], rgb[3])
EndSub
Sub Intermediate
' param a - the first value
' param b - the second value
' param k - ratio between a and b (0 ≦ k ≦ 1)
' return c - the intermediate value between a and b
c = a * (1 - k) + b * k
EndSub
Sub IntermediatePoint
' param pointA - the first point
' param pointB - the second point
' param k - ratio between a and b (0 ≦ k ≦ 1)
' return pointC - the intermidiate point between pointA and pointB
n = Array.GetItemCount(pointA)
index = Array.GetAllIndices(pointA)
For j = 1 To n
a = pointA[index[j]]
b = pointB[index[j]]
Intermediate()
pointC[index[j]] = c
EndFor
EndSub
Sub IntermediateColor
' param a - the first color
' param b - the second color
' param k - ratio between a and b (0 ≦ k ≦ 1)
' return c - the intermediate color between colorA and colorB
For j = 1 To 3
hex = Text.GetSubText(colorA, j * 2, 2)
Hex2Dec()
a = dec
hex = Text.GetSubText(colorB, j * 2, 2)
Hex2Dec()
b = dec
Intermediate()
rgb[j] = c
EndFor
colorC = GraphicsWindow.GetColorFromRGB(rgb[1], rgb[2], rgb[3])
EndSub
Sub Hex2Dec
' param hex
' return dec
len = Text.GetLength(hex)
dec = 0
For i = 1 To len
dec = dec * 16 + Text.GetIndexOf("123456789ABCDEF", Text.GetSubText(Text.ConvertToUpperCase(hex), i, 1))
EndFor
EndSub