Skip to content

Commit b9ec4cb

Browse files
committed
[css-color-5] Add diagram showing hue-rotated color going oog
1 parent 89a98ec commit b9ec4cb

3 files changed

Lines changed: 160 additions & 0 deletions

File tree

css-color-5/Overview.bs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,22 @@ Selecting the most contrasting color: the ''color-contrast()'' function {#colorc
608608
contrast = (Y<sub>l</sub> + 0.05) / (Y<sub>d</sub> + 0.05)
609609
where Y<sub>d</sub> is the luminance of the darker color in the pair
610610
and Y<sub>l</sub> is the luminance of the lighter color.
611+
The factor 0.05 represents the luminance contribution of the viewing flare.
612+
613+
<div class="example">
614+
Suppose that the single color was
615+
616+
<pre class="lang-css">color(display-p3 0.38 0.11 0.05)</pre>
617+
618+
while the first color in the list was
619+
620+
<pre class="lang-css">yellow</pre>
621+
622+
The calculation is as follows:
623+
* <span class="swatch" style="--color: rgb(41.482% 7.941% 1.375%)"></span> color(display-p3 0.38 0.11 0.05) is <span class="swatch" style="--color: rgb(41.482% 7.941% 1.375%)"></span> color(xyz 0.06191 0.03568 0.00463) so the relative luminance is <b>0.03568</b>
624+
* <span class="swatch" style="--color: yellow"></span> yellow is <span class="swatch" style="--color: yellow"></span> rgb(100% 100% 0%) which is <span class="swatch" style="--color: yellow"></span> color(xyz 0.76998 0.92781 0.13853) so the relative luminance is <b>0.92781</b>
625+
* the contrast is (0.92781 + 0.05) / (0.03568 + 0.05) = <b>11.4123</b>
626+
</div>
611627

612628

613629
It then selects from that list
@@ -1103,6 +1119,20 @@ However, unlike HSL, manipulations are not guaranteed to be in-gamut.
11031119

11041120
The closest color inside the sRGB gamut would be <span class="swatch" style="--color: rgb(0% 64.2% 66.3%)"></span> lch(60.71% 37.56 201.1)
11051121
which is <span class="swatch" style="--color: rgb(0% 64.2% 66.3%)"></span> rgb(0% 64.2% 66.3%). The difference in chroma (37.5, instead of 90) is huge.
1122+
1123+
<figure>
1124+
<img src="images/LCH-rotation-oog.svg"
1125+
alt="Diagram of CH plane showing relative color manipulation">
1126+
<figcaption>
1127+
This diagram shows the sRGB gamut, in the CIE ab plane.
1128+
Small circles indicate the primary and secondary color.
1129+
The <span class="swatch" style="--color: rgb(86.1% 33.4% 97.6%)"></span>
1130+
origin color, shown as a large circle, is in gamut for sRGB;
1131+
becomes <span class="swatch oog" style="--color: #AAA"></span> out of gamut (shown as a grey fill and red border)
1132+
when the LCH hue is rotated -120°.
1133+
The gamut-mapped <span class="swatch" style="--color: rgb(0% 64.2% 66.3%)"></span> result has much lower chroma.
1134+
</figcaption>
1135+
</figure>
11061136
</div>
11071137

11081138
<h3 id="relative-OKLCH">Relative OKLCH colors</h3>
Lines changed: 104 additions & 0 deletions
Loading

css-color-5/images/arcmaker.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script>
2+
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
3+
var angleInRadians = (angleInDegrees) * Math.PI / 180.0;
4+
5+
return {
6+
x: centerX + (radius * Math.cos(angleInRadians)),
7+
y: -1 * (centerY + (radius * Math.sin(angleInRadians)))
8+
};
9+
}
10+
11+
function describeArc(x, y, radius, startAngle, endAngle){
12+
13+
var start = polarToCartesian(x, y, radius, endAngle);
14+
var end = polarToCartesian(x, y, radius, startAngle);
15+
16+
var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
17+
18+
var d = [
19+
"M", start.x, start.y,
20+
"A", radius, radius, 0, largeArcFlag, 0, end.x, end.y
21+
].join(" ");
22+
23+
return d;
24+
}
25+
console.log(describeArc(0,0, 60, 200, 320));
26+
</script>

0 commit comments

Comments
 (0)