summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gradient-text/gradient-text.sty
blob: 56010b4c9bf326ae43553eeb7dc8d080e92f554e (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
32
33
34
35
36
% Copyright (C) 2022-2023 by Sicheng Du <siddsc@foxmail.com>
% This project is distributed under the LaTeX Project Public License, version 1.3c.
%-------------------------%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gradient-text}[2023/1/17]
\ExplSyntaxOn
\clist_new:N\l_gtext_FirstRGB_clist
\clist_new:N\l_gtext_LastRGB_clist
\int_new:N\l_gtext_MaxIndex_int
\int_new:N\l_gtext_Ratio_int
\newcommand{\gr@dientRGB}[7]{
  \int_set:Nn\l_gtext_MaxIndex_int{\int_eval:n{\str_count:n{#1}}}
  \int_step_inline:nnn{1}{\l_gtext_MaxIndex_int}{
      \exp_args:Ne\str_if_eq:nnTF{\str_item:Nn{#1}{##1}}{~}{}{
        \int_set:Nn\l_gtext_Ratio_int{\int_eval:n{\l_gtext_Ratio_int+1}}
      }
        \color_select:nn{RGB}{
          \int_eval:n{(\int_use:N\l_gtext_Ratio_int*#5+(\l_gtext_MaxIndex_int-##1)*#2)/\l_gtext_MaxIndex_int},
          \int_eval:n{(\int_use:N\l_gtext_Ratio_int*#6+(\l_gtext_MaxIndex_int-##1)*#3)/\l_gtext_MaxIndex_int},
          \int_eval:n{(\int_use:N\l_gtext_Ratio_int*#7+(\l_gtext_MaxIndex_int-##1)*#4)/\l_gtext_MaxIndex_int}
      }\str_item:Nn{#1}{##1}
  }
}
\NewDocumentCommand\gradientRGB{mmm}{{
  \clist_set:Nn\l_gtext_FirstRGB_clist {#2}
  \clist_set:Nn\l_gtext_LastRGB_clist {#3}
  \gr@dientRGB{#1}
  {\clist_item:Nn\l_gtext_FirstRGB_clist{1}}
  {\clist_item:Nn\l_gtext_FirstRGB_clist{2}}
  {\clist_item:Nn\l_gtext_FirstRGB_clist{3}}
  {\clist_item:Nn\l_gtext_LastRGB_clist{1}}
  {\clist_item:Nn\l_gtext_LastRGB_clist{2}}
  {\clist_item:Nn\l_gtext_LastRGB_clist{3}}
}}
\ExplSyntaxOff
%---End of package code---%