我必须正确混合两种颜色,这样才能生成一个单词,其字母用两种颜色(比如 x 和 y)着色,这样在开始的时候,x 在字母上占主导地位,随着前进到结尾而逐渐褪色,最后一个字母的颜色与第一个字母的颜色相反。
为了让事情变得更简单:
def calc(x):
init_val = 100/(x+1)
result = []
for i in range(1, x+1):
result.append((n:=init_val*i, 100-n))
return result
while True:
word = input("Enter the word: ") # criticized
colors = input("Enter 2 colors (separated by space): ") # Blue Fuchsia
for number, (mix1, mix2) in enumerate(calc(len(word))):
print(r"{\color{"+f'{colors.split(" ")[0]}!{mix1}!{colors.split(" ")[1]}!{mix2}'+"}"
+word[number]+"}")
将其放入 LaTeX 中:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\begin{document}
{\color{Blue!9.090909090909092!Fuchsia!90.9090909090909}c}
{\color{Blue!18.181818181818183!Fuchsia!81.81818181818181}r}
{\color{Blue!27.272727272727273!Fuchsia!72.72727272727272}i}
{\color{Blue!36.36363636363637!Fuchsia!63.63636363636363}t}
{\color{Blue!45.45454545454546!Fuchsia!54.54545454545454}i}
{\color{Blue!54.54545454545455!Fuchsia!45.45454545454545}c}
{\color{Blue!63.63636363636364!Fuchsia!36.36363636363636}i}
{\color{Blue!72.72727272727273!Fuchsia!27.272727272727266}z}
{\color{Blue!81.81818181818183!Fuchsia!18.181818181818173}e}
{\color{Blue!90.90909090909092!Fuchsia!9.09090909090908}d}
\end{document}
和都是深色Blue
,Fuchsia
但混合后最终变成浅色。如何解决这个问题?
答案1
删除第二组数字。您实际上在这里混合了第三种颜色(白色)。不完整混合表达式只是完整混合表达式的缩写,其中最后一种颜色 = 白色。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\begin{document}
{\color{Blue!9.090909090909092!Fuchsia!90.9090909090909}c}
{\color{Blue!18.181818181818183!Fuchsia!81.81818181818181}r}
{\color{Blue!27.272727272727273!Fuchsia!72.72727272727272}i}
{\color{Blue!36.36363636363637!Fuchsia!63.63636363636363}t}
{\color{Blue!45.45454545454546!Fuchsia!54.54545454545454}i}
{\color{Blue!54.54545454545455!Fuchsia!45.45454545454545}c}
{\color{Blue!63.63636363636364!Fuchsia!36.36363636363636}i}
{\color{Blue!72.72727272727273!Fuchsia!27.272727272727266}z}
{\color{Blue!81.81818181818183!Fuchsia!18.181818181818173}e}
{\color{Blue!90.90909090909092!Fuchsia!9.09090909090908}d}
{\color{Blue!9.090909090909092!Fuchsia}c}
{\color{Blue!18.181818181818183!Fuchsia}r}
{\color{Blue!27.272727272727273!Fuchsia}i}
{\color{Blue!36.36363636363637!Fuchsia}t}
{\color{Blue!45.45454545454546!Fuchsia}i}
{\color{Blue!54.54545454545455!Fuchsia}c}
{\color{Blue!63.63636363636364!Fuchsia}i}
{\color{Blue!72.72727272727273!Fuchsia}z}
{\color{Blue!81.81818181818183!Fuchsia}e}
{\color{Blue!90.90909090909092!Fuchsia}d}
\end{document}