summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gradient-text/gradient-text.sty
blob: 62494481f4b46a340cd93628a29086b143977275 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gradient-text}[2022/12/24]
\ExplSyntaxOn
\clist_new:N\l_FirstRGB_int \clist_new:N\l_LastRGB_int
\int_new:N\l_MaxIndex\int_new:N\l_Ratio
\newcommand{\@radientR@B}[7]{
  \int_set:Nn\l_MaxIndex{\int_eval:n{\str_count:n{#1}}}
  \int_step_inline:nnn{1}{\l_MaxIndex}{
      \exp_args:Ne\str_if_eq:nnTF{\str_item:Nn{#1}{##1}}{~}{}{
        \int_set:Nn\l_Ratio{\int_eval:n{\l_Ratio+1}}
      }
        \color_select:nn{RGB}{
          \int_eval:n{(\int_use:N\l_Ratio*#5+(\l_MaxIndex-##1)*#2)/\l_MaxIndex},
          \int_eval:n{(\int_use:N\l_Ratio*#6+(\l_MaxIndex-##1)*#3)/\l_MaxIndex},
          \int_eval:n{(\int_use:N\l_Ratio*#7+(\l_MaxIndex-##1)*#4)/\l_MaxIndex}
      }\str_item:Nn{#1}{##1}
  }
}

\NewDocumentCommand\gradientRGB{mmm}{{
  \clist_set:Nn\l_FirstRGB_int #2
  \clist_set:Nn\l_LastRGB_int #3
  \@radientR@B{#1}
  {\clist_item:Nn\l_FirstRGB_int{1}}
  {\clist_item:Nn\l_FirstRGB_int{2}}
  {\clist_item:Nn\l_FirstRGB_int{3}}
  {\clist_item:Nn\l_LastRGB_int{1}}
  {\clist_item:Nn\l_LastRGB_int{2}}
  {\clist_item:Nn\l_LastRGB_int{3}}
}}
\ExplSyntaxOff