我正在尝试绘制一个混合颜色的网格,它会根据 x 和 y 坐标 (MWE) 而变化:
\documentclass[border=4pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \x/\perc in {0/33.3,1.5/66.6}
\foreach \y/\percy in {0/0.9,1.5/1.1}
\fill[color = green!{\percy*\perc}!red] (\x,\y) rectangle +(1.5cm,1.5cm);
\end{tikzpicture}
\end{document}
然而这并不起作用,因为它会产生:
关于如何使乘法运算起作用,您有什么想法吗?
答案1
\documentclass[border=4pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \x/\perc in {0/33.3,1.5/66.6}
{\foreach \y/\percy [evaluate=\percy as \percxy using {int(\perc*\percy)}] in {0/0.9,1.5/1.1}
{\fill[color = green!\percxy!red] (\x,\y) rectangle +(1.5cm,1.5cm);}}
\end{tikzpicture}
\end{document}