What I think I need to represent what I intended idiomatically could be only something like:
Public Module WebSafeColors
// Find nearest web safe value for a channel
Private Function NearestWebSafe(oneColorValue As Integer) As Integer
Var near As Integer = oneColorValue \ 51
If oneColorValue mod 51 > 25 Then near = near + 1 // the nearest is the next one above
Return near * 51
End Function
// receive a color, return the nearest web safe of it
Function WebSafeColor(c As Color) As Color
Return Color.RGB(NearestWebSafe(c.Red), NearestWebSafe(c.Green), NearestWebSafe(c.Blue), c.Alpha)
End Function
// Receive an index (0 to 215) and return the equivalent web safe color
Function WebSafeColor(idx As Integer) As Color
Var r,g,b As Integer
If idx < 0 Then idx = 0
If idx > 215 Then idx = 215
// Find a WebSafe RGB based on its index and a virtual web safe color distribution
b = idx mod 6 * 51
idx = idx \ 6
g = idx mod 6 * 51
r = idx \ 6 * 51
Return Color.RGB(r, g, b)
End Function
// compose a web safe color passing each RGB channel value
Function WebSafeColor(r As Integer, g As Integer, b As Integer, a As Integer = 0) As Color
Return Color.RGB(NearestWebSafe(r),NearestWebSafe(g),NearestWebSafe(b), a)
End Function
// Receive a color and return the one byte value (0to 215) equivalent
Function WebSafeColorIndex(c As Color) As Integer
// Calculate a virtual index for a Web Safe color (Palette of 216 colors)
Return NearestWebSafe(c.Red) \ 51 * 36 + NearestWebSafe(c.Green) \ 51 * 6 + NearestWebSafe(c.Blue) \ 51
End Function
End Module
But this way Xojo probably will complain about something.