Skip to content

Commit 7148b31

Browse files
committed
[css-color-4] Add descriptions and example for hue interpolation keywords. #9207
1 parent 56a12f3 commit 7148b31

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed

css-color-4/Overview.bs

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4863,7 +4863,7 @@ Hue Interpolation</h3>
48634863

48644864
For color functions with a hue angle (LCH, HSL, HWB etc), there are multiple ways to interpolate.
48654865
As arcs greater than 360&deg; are rarely desirable,
4866-
by default hue angles are fixed up prior to interpolation
4866+
hue angles are fixed up prior to interpolation
48674867
so that per-component interpolation is done over less than 360&deg;, often less than 180&deg;.
48684868

48694869
Host syntax can specify any of the following algorithms for hue interpolation
@@ -4887,12 +4887,25 @@ Hue Interpolation</h3>
48874887
</wpt>
48884888

48894889
Note: As a reminder,
4890-
if the interpolating colors were not already in the specified interpolation syntax,
4890+
if the interpolating colors were not already in the specified interpolation color space,
48914891
then converting them will turn any [=powerless components=] into [=missing components=].
48924892

48934893
<h4 id="hue-shorter">
48944894
<dfn export>shorter</dfn></h4>
48954895

4896+
Hue angles are interpolated to take the <em>shorter</em> of the two arcs
4897+
between the starting and ending hues.
4898+
4899+
<div class="example" id="ex-shorter">
4900+
For example, the midpoint when interpolating in Oklch from a red
4901+
<span class="swatch" style="--color: rgb(93.22% 7.98% 0.485%)"></span>&nbsp;oklch(0.6 0.24 30) to a yellow
4902+
<span class="swatch" style="--color: rgb(89.07% 72.28% 19.23%)"></span>&nbsp;oklch(0.8 0.15 90)
4903+
would be at a hue angle of (30 + 90) / 2 = 60 degrees,
4904+
along the shorter arc between the two colors,
4905+
giving a deep orange
4906+
<span class="swatch" style="--color: rgb(87.66% 51.96% 0%)"></span>&nbsp;oklch(0.7 0.195 60)
4907+
</div>
4908+
48964909
Angles are adjusted so that |θ₂ - θ₁| ∈ [-180, 180]. In pseudo-Javascript:
48974910
<pre>
48984911
if (θ₂ - θ₁ > 180) {
@@ -4906,6 +4919,19 @@ Hue Interpolation</h3>
49064919
<h4 id="hue-longer">
49074920
<dfn export>longer</dfn></h4>
49084921

4922+
Hue angles are interpolated to take the <em>longer</em> of the two arcs
4923+
between the starting and ending hues.
4924+
4925+
<div class="example" id="ex-longer">
4926+
For example, the midpoint when interpolating in Oklch from a red
4927+
<span class="swatch" style="--color: rgb(93.22% 7.98% 0.485%)"></span>&nbsp;oklch(0.6 0.24 30) to a yellow
4928+
<span class="swatch" style="--color: rgb(89.07% 72.28% 19.23%)"></span>&nbsp;oklch(0.8 0.15 90)
4929+
would be at a hue angle of (30 + 360 + 90) / 2 = 240 degrees,
4930+
along the longer arc between the two colors,
4931+
giving a sky blue
4932+
<span class="swatch" style="--color: rgb(0% 66.25% 100%)"></span>&nbsp;oklch(0.7 0.195 240)
4933+
</div>
4934+
49094935
Angles are adjusted so that |θ₂ - θ₁| ∈ {(-360, -180], [180, 360)}. In pseudo-Javascript:
49104936
<pre>
49114937
if (0 < θ₂ - θ₁ < 180) {
@@ -4919,6 +4945,33 @@ Hue Interpolation</h3>
49194945
<h4 id="hue-increasing">
49204946
<dfn export>increasing</dfn></h4>
49214947

4948+
Hue angles are interpolated so that,
4949+
as they progress from the first color to the second,
4950+
the angle is always <em>increasing</em>.
4951+
4952+
Depending on the difference between the two angles,
4953+
this will either look the same as <em>shorter</em> or as <em>longer.</em>
4954+
However, if one of the hue angles is being animated,
4955+
and the hue angle difference passes through 180 degrees,
4956+
the interpolation will not flip to the other arc.
4957+
4958+
<div class="example" id="ex-increasing">
4959+
For example, the midpoint when interpolating in Oklch from a deep brown
4960+
<span class="swatch" style="--color: rgb(57.92% 29.44% 25.11%)"></span>&nbsp;oklch(0.5 0.1 30) to a turquoise
4961+
<span class="swatch" style="--color: rgb(26.29% 69.89% 67.49%)"></span>&nbsp;oklch(0.7 0.1 190)
4962+
would be at a hue angle of (30 + 190) / 2 = 110 degrees,
4963+
giving a khaki
4964+
<span class="swatch" style="--color: rgb(51.73% 52.26% 22.03%)"></span>&nbsp;oklch(0.6 0.1 110).
4965+
4966+
However, if the hue of second color is animated to
4967+
<span class="swatch" style="--color: rgb(33.09% 66.63% 81.81%)"></span>&nbsp;oklch(0.7 0.1 230),
4968+
the midpoint of the interpolation will be (30 + 230) / 2 = 130 degrees,
4969+
continuing in the same increasing direction,
4970+
giving another green
4971+
<span class="swatch" style="--color: rgb(42.44% 54.95% 28.93%)"></span>&nbsp;oklch(0.6 0.1 130)
4972+
rather than flipping to the opponent color part-way through the animation.
4973+
</div>
4974+
49224975
Angles are adjusted so that |θ₂ - θ₁| ∈ [0, 360). In pseudo-Javascript:
49234976
<pre>
49244977
if (θ₂ < θ₁) {
@@ -4929,6 +4982,33 @@ Hue Interpolation</h3>
49294982
<h4 id="hue-decreasing">
49304983
<dfn export>decreasing</dfn></h4>
49314984

4985+
Hue angles are interpolated so that,
4986+
as they progress from the first color to the second,
4987+
the angle is always <em>decreasing</em>.
4988+
4989+
Depending on the difference between the two angles,
4990+
this will either look the same as <em>shorter</em> or as <em>longer.</em>
4991+
However, if one of the hue angles is being animated,
4992+
and the hue angle difference passes through 180 degrees,
4993+
the interpolation will not flip to the other arc.
4994+
4995+
<div class="example" id="ex-decreasing">
4996+
For example, the midpoint when interpolating in Oklch from a deep brown
4997+
<span class="swatch" style="--color: rgb(57.92% 29.44% 25.11%)"></span>&nbsp;oklch(0.5 0.1 30) to a turquoise
4998+
<span class="swatch" style="--color: rgb(26.29% 69.89% 67.49%)"></span>&nbsp;oklch(0.7 0.1 190)
4999+
would be at a hue angle of (30 + 360 + 190) / 2 = 290 degrees,
5000+
giving a purple
5001+
<span class="swatch" style="--color: rgb(49.98% 46.03% 72.08%)"></span>&nbsp;oklch(0.6 0.1 290).
5002+
5003+
However, if the hue of second color is animated to
5004+
<span class="swatch" style="--color: rgb(33.09% 66.63% 81.81%)"></span>&nbsp;oklch(0.7 0.1 230),
5005+
the midpoint of the interpolation will be (30 +360 + 230) / 2 = 310 degrees,
5006+
continuing in the same decreasing direction,
5007+
giving another purple
5008+
<span class="swatch" style="--color: rgb(57.47% 43.44% 67.8%)"></span>&nbsp;oklch(0.6 0.1 310)
5009+
rather than flipping to the opponent color part-way through the animation.
5010+
</div>
5011+
49325012
Angles are adjusted so that |θ₂ - θ₁| ∈ (-360, 0]. In pseudo-Javascript:
49335013
<pre>
49345014
if (θ₁ < θ₂) {

0 commit comments

Comments
 (0)