This has been bugging me since the very beginning, but I still don’t know the answer. And can this be changed/added.
Here’s what it might look like starting from red:
![]()
No clue, I’d guess it just looked nice to whoever made the color map. I can’t seem to find which color map this came from, but pretty much every other one I recognize as in the current color map literature. i.e., Typst team didn’t come up with them.
My one and only representation of rainbow is what I’ve learned from very early years and how a rainbow actually looks like, AFAIK.
#set page(width: auto, height: auto, margin: 0pt)
#let stripe(..color-map) = block(
width: 1cm,
height: 5cm,
fill: gradient.linear(angle: 90deg, ..color-map),
)
#grid(
columns: 3,
stripe(..color.map.rainbow),
stripe(..color.map.rainbow.slice(55)),
stripe(
rgb("#f00"),
rgb("#ff7900"),
rgb("#ff0"),
rgb("#0f0"),
rgb("#0ff"),
rgb("#00f"),
rgb("#7900ff"),
),
)
I also can’t answer authoritatively, but I’d assume that the reason relates to magenta (#f0f) not actually being a color of the rainbow, just the color used to join the rainbow into a circle (Magenta—In optics and color science). The extreme color at the blue end of the spectrum is violet, which Wikipedia gives as #8000ff.
So imo there are two sensible choices: make an optical rainbow from red to violet, or a visual rainbow from magenta to magenta. In the latter, red, wouldn’t be the starting color—but why the “canonical” rainbow (which seems to include magenta) apparently splits up the wheel at violet is a mystery to me.
I answer the actual question at the end. tldr, nothing is real and choices are arbitrary, but some matter for different reasons.
how a rainbow actually looks like
Nitpick: to depict the most commonly coded rainbow in programming/art software-land, it should loop back around to red at the end.
But I do think the popular “programmer’s rainbow” (aka the Hue in Hue/Saturation/Value aka the slider in common HSL color pickers aka the circumference of common HSV (circle) color pickers[1]) looks similar but definitely differs from a real rainbow’s colors, which unless I’m misinterpreting, is the in the graphic at Visible spectrum - Wikipedia (oh shoot, realized SillyFreak’s link also has this image).
So imo there are two sensible choices: make an optical rainbow from red to violet, or a visual rainbow from magenta to magenta.
Anyways, it makes sense to me that it just happened so that we ended up starting out with red in the classic “programmer’s rainbow” because RGB is conceptually a three-tuple of floats[2] and red is what you get when you set the zeroth thing to one, and us programmers love starting out with the zeroth things. I don’t think magenta to magenta makes more sense to a programmer’s brain, even if it may or may not from a color science standpoint.
Ok another side tangent, I took a harder look at the perceptual color space OKHSV from [1:1], and they do actually start at magenta lmao. So that’s pretty cool that @SillyFreak thought of that.
Wait a minute… I took another look at Typst’s rainbow color map, and is it just a shifted version of the OKHSV map? Might ping a dev on this. Doesn’t seem documented.
But to answer the original question, since the rainbow color map is a cyclic map, it doesn’t really matter where it starts. Red is historically correct (e.g. HSV) and is informed by the definition of RGB, magenta may make more sense (e.g. OKHSV), and maybe the Typst devs just thought purple looked pretty, or was otherwise a reasonable place to
Disclosure: I’m making up the “programmers start with zero index → RGB zero index is red → rainbow starts with red” thing. It’s speculation.
Yeah yeah, they’re often and historically
u8s, whatever. ↩︎
Well, the last one should be purple, so I fixed it.
Actually, if you remove the purple and pink from the beginning, it kinda looks similar, but very washed and pastel-like/desaturated.
I explicitly then stated that it’s for actual (optical?) rainbow, so this does not apply.
Why is it cyclic? It’s literally the only one. All others aren’t. And this also shouldn’t, since it supposed to start at red and end with purple. So having a more accurate rainbow will actually make it fit in with all other color maps.
If it’s cyclic to literally be the only one that is useful for pretty conic gradients, while all others are useless for that, then that’s a very weak argument.
