TeX - LaTeX Asked on February 11, 2021
I want to define a new colour (myorange
) by changing the hue
value of a previously given colour (oldcolour
), thus maintaining its original saturation and brightness. Is there a way for doing this?
I can think of two strategies. First, having a function changehue
that returns a colour from another, but with a hue defined by the user. It would be used as follows:
colorlet{myorange}{changehue{oldcolour}{30}}
Or maybe:
colorlet{myorange}{changehue{oldcolour}{orange}}
In this last case, changehue
would extract the hue of orange
and plug it into the code. This way would be better for me.
In the second strategy, we just define the colour with the definecolor
with the hsb
colour model with the help of functions for extracting the hue, saturation and brightness of the colour previously given.
definecolor{myorange}{hsb}{hue{orange}, saturation{oldcolour}, brightness{oldcolour}}
I strongly prefer this second strategy, which is the way presupposed by my question. It would be useful to know if commands like hue
, saturation
, and brightness
exist or can be defined.
Thanks in advance for your help.
This might be a partial answer. You can define a color series and vary, say, the hue value. The perhaps more important information is that extractcolorspecs
allows you to extract the color specifications of a given color. This can be converted to a given color scheme with convertcolorspec
. The last two commands have been merged to the convertdirectly
command, which I am recycling here.
documentclass{article}
usepackage{xcolor}
% from https://tex.stackexchange.com/a/283618
newcommand{convertdirectly}[3][hsb]{begingroup%
extractcolorspecs{#2}{modelcmd}{colorcmd}%
convertcolorspec{modelcmd}{colorcmd}{#1}{tmp}%
message{#2 in #1 is tmp^^J}%
aftergroupdef#3tmp}
defFirst#1,#2,#3{#1}
defSecond#1,#2,#3{#2}
defThird#1,#2,#3{#3}
newcommand{hue}[1]{convertdirectly{#1}{tmp}%
expandafterFirsttmp}
newcommand{Hue}[2]{begingroupconvertdirectly{#1}{tmp}%
edefres{expandafterFirsttmp}%
aftergroupdef#2res}
newcommand{saturation}[1]{convertdirectly{#1}{tmp}%
expandafterSecondtmp}
newcommand{Saturation}[2]{begingroupconvertdirectly{#1}{tmp}%
edefres{expandafterSecondtmp}%
aftergroupdef#2res}
newcommand{brightness}[1]{convertdirectly{#1}{tmp}%
expandafterThirdtmp}
newcommand{Brightness}[2]{begingroupconvertdirectly{#1}{tmp}%
edefres{expandafterThirdtmp}%
aftergroupdef#2res}
newcounter{myc}
begin{document}
definecolorseries{changehue}{hsb}{step}{orange}{0,0.1,0}
resetcolorseries[12]{changehue}%
loopstepcounter{myc}colorlet{mycolor}{changehue!![numbervalue{myc}]}%
extractcolorspecs{mycolor}{modelcmd}{colorcmd}%
model=textcolor{mycolor}{modelcmd},%
color=textcolor{mycolor}{colorcmd}parifnumvalue{myc}<11repeat
the hsb ``code'' of orange is convertdirectly{orange}{hsborange}hsborange
the hsb ``code'' of brown is convertdirectly{brown}{hsbbrown}hsbbrown
hue of orange=hue{orange}
saturation of orange=saturation{orange}
brightness of orange=brightness{orange}
Hue{orange}{myhue}Saturation{blue}{mysaturation}Brightness{brown}mybrightness
definecolor{myorange}{hsb}{myhue,mysaturation,mybrightness}
textcolor{myorange}{Test}
end{document}
Answered by user194703 on February 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP