summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLynn <lynn@foldr.moe>2023-07-05 11:26:50 +0200
committerGitHub <noreply@github.com>2023-07-05 11:26:50 +0200
commit9a9da806656fe70dde8827f8afc5dd9dac8f7cb0 (patch)
treec93422b364a759297771e9718745db935a8b14fa /tests
parent5fdd62141ff1dd19917e93b60f4dff5884be2020 (diff)
Color mixing function (#1332)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/typ/compute/construct.typ32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/typ/compute/construct.typ b/tests/typ/compute/construct.typ
index f094b6b2..ddd4c591 100644
--- a/tests/typ/compute/construct.typ
+++ b/tests/typ/compute/construct.typ
@@ -14,6 +14,26 @@
#test(rgb("#133337").negate(), rgb(236, 204, 200))
#test(white.lighten(100%), white)
+// Color mixing, in Oklab space by default.
+#test(color.mix(rgb("#ff0000"), rgb("#00ff00")), rgb("#d0a800"))
+#test(color.mix(rgb("#ff0000"), rgb("#00ff00"), space: "oklab"), rgb("#d0a800"))
+#test(color.mix(rgb("#ff0000"), rgb("#00ff00"), space: "srgb"), rgb("#808000"))
+
+#test(color.mix(red, green, blue), rgb("#909282"))
+#test(color.mix(red, blue, green), rgb("#909282"))
+#test(color.mix(blue, red, green), rgb("#909282"))
+
+// Mix with weights.
+#test(color.mix((red, 50%), (green, 50%)), rgb("#c0983b"))
+#test(color.mix((red, 0.5), (green, 0.5)), rgb("#c0983b"))
+#test(color.mix((red, 5), (green, 5)), rgb("#c0983b"))
+#test(color.mix((green, 5), (white, 0), (red, 5)), rgb("#c0983b"))
+#test(color.mix((red, 100%), (green, 0%)), red)
+#test(color.mix((red, 0%), (green, 100%)), green)
+#test(color.mix((rgb("#aaff00"), 25%), (rgb("#aa00ff"), 75%), space: "srgb"), rgb("#aa40bf"))
+#test(color.mix((rgb("#aaff00"), 50%), (rgb("#aa00ff"), 50%), space: "srgb"), rgb("#aa8080"))
+#test(color.mix((rgb("#aaff00"), 75%), (rgb("#aa00ff"), 25%), space: "srgb"), rgb("#aabf40"))
+
---
// Test gray color conversion.
// Ref: true
@@ -41,6 +61,18 @@
#rgb(10%, 20%, 30%, false)
---
+// Error: 12-24 expected float or ratio, found string
+#color.mix((red, "yes"), (green, "no"))
+
+---
+// Error: 12-23 expected a color or color-weight pair
+#color.mix((red, 1, 2))
+
+---
+// Error: 31-38 expected "oklab" or "srgb"
+#color.mix(red, green, space: "cyber")
+
+---
// Ref: true
#let envelope = symbol(
"🖂",