HSV

From Xojo Documentation

Method

Returns a Color object based on the HSV (hue, saturation, value) color model with the passed level of transparency. Use the new form of the Picture constructor to create pictures that support the alpha channel or convert existing pictures to the new format using the code described in HasAlphaChannel.

Syntax

result=HSV(hue, saturation, value [, alpha = 0])

Part Type Description
result Color An object that represents the color based on the hue, saturation, value, and transparency values.
hue Double The value of Hue in the color (0-1).
saturation Double The value of Saturation in the color (0-1).
value Double The value of Value (brightness or lightness) in the color (0-1).
alpha Integer The value of transparency in the color (0-255). Zero is completely opaque and 255 is fully transparent. If omitted, the default is 0.

Notes

The HSV function returns a color object based on the amounts of Hue, Saturation, Value and Transparency (alpha channel) passed. The colors are amounts are represented by doubles between 0 and 1. Alpha is an Integer from 0-255.

Colors can also be created using the RGB or CMY models. You can also use the &c literal to specify a color using the RGB model. All alternatives support the optional transparency parameter.

Examples

This example uses the HSV function to assign a Color to the FillColor property. This code is in the Paint event of a Canvas or a Window.

g.FillColor = HSV(0.8, 0.5, 0.75)

Transparency

The following example draws sample color patches in a Canvas with varying levels of transparency. With the HSV function, the range is from 0 to 255. Zero is completely opaque and 255 is completely transparent. The code is in the Paint event.

g.ForeColor = HSV(1.0, 1.0, 1.0) // red, no transparency
g.DrawRect(0, 0, 200, 50)

g.FillRect(0, 0, 200, 50)
g.ForeColor = HSV(0, 0, 0)
g.DrawString("Translucent = 0", 210, 10)

g.ForeColor = HSV(1.0, 1.0, 1.0, 76) // transparency = 0.3

g.FillRect(0, 70, 200, 50)
g.ForeColor = HSV(0, 0, 0)
g.DrawString("Translucent = 30%", 210, 80)

g.ForeColor = HSV(1.0, 1.0, 1.0, 127) // transparency = 0.5

g.FillRect(0, 140, 200, 50)
g.ForeColor = HSV(0, 0, 0, 0)
g.DrawString("Translucent = 50%", 210, 150)

g.ForeColor = HSV(1.0, 1.0, 1.0, 178) // transparency = 0.7

g.FillRect(0, 210, 200, 50)
g.ForeColor = HSV(0, 0, 0, 0)
g.DrawString("Translucent = 70%", 210, 220)

g.ForeColor = HSV(1.0, 1.0, 1.0, 229) // transparency = 0.9

g.FillRect(0, 280, 200, 50)
g.ForeColor = HSV(0, 0, 0, 0)
g.DrawString("Translucent = 90%", 210, 290)

The result is shown here.

Sample red color patches illustrating transparency.

See Also

Color data type, CMY, RGB, SelectColor functions; &c literal.