|
@@ -8,9 +8,11 @@ struct Color {
|
|
blue: Scalar,
|
|
blue: Scalar,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+@description("Create a `Color` from RGB (red, green, blue) values in the range $[0, 256)$.")
|
|
fn rgb(red: Scalar, green: Scalar, blue: Scalar) -> Color =
|
|
fn rgb(red: Scalar, green: Scalar, blue: Scalar) -> Color =
|
|
Color { red: red, green: green, blue: blue }
|
|
Color { red: red, green: green, blue: blue }
|
|
|
|
|
|
|
|
+@description("Create a `Color` from a (hexadecimal) value, e.g. `color(0xff7700)`")
|
|
fn color(rgb_hex: Scalar) -> Color =
|
|
fn color(rgb_hex: Scalar) -> Color =
|
|
rgb(
|
|
rgb(
|
|
floor(rgb_hex / 256^2),
|
|
floor(rgb_hex / 256^2),
|
|
@@ -20,12 +22,15 @@ fn color(rgb_hex: Scalar) -> Color =
|
|
fn _color_to_scalar(color: Color) -> Scalar =
|
|
fn _color_to_scalar(color: Color) -> Scalar =
|
|
color.red * 0x010000 + color.green * 0x000100 + color.blue
|
|
color.red * 0x010000 + color.green * 0x000100 + color.blue
|
|
|
|
|
|
|
|
+@description("Convert a color to its RGB representation, e.g. `cyan -> color_rgb`")
|
|
fn color_rgb(color: Color) -> String =
|
|
fn color_rgb(color: Color) -> String =
|
|
"rgb({color.red}, {color.green}, {color.blue})"
|
|
"rgb({color.red}, {color.green}, {color.blue})"
|
|
|
|
|
|
|
|
+@description("Convert a color to its RGB floating point representation, e.g. `cyan -> color_rgb_float`")
|
|
fn color_rgb_float(color: Color) -> String =
|
|
fn color_rgb_float(color: Color) -> String =
|
|
"rgb({color.red / 255:.3}, {color.green / 255:.3}, {color.blue / 255:.3})"
|
|
"rgb({color.red / 255:.3}, {color.green / 255:.3}, {color.blue / 255:.3})"
|
|
|
|
|
|
|
|
+@description("Convert a color to its hexadecimal representation, e.g. `rgb(225, 36, 143) -> color_hex`")
|
|
fn color_hex(color: Color) -> String =
|
|
fn color_hex(color: Color) -> String =
|
|
str_append("#", str_replace(str_replace("{color -> _color_to_scalar -> hex:>8}", "0x", ""), " ", "0"))
|
|
str_append("#", str_replace(str_replace("{color -> _color_to_scalar -> hex:>8}", "0x", ""), " ", "0"))
|
|
|
|
|