我想用 TikZ 包绘制并填充下面的心形。我使用阴影选项绘制整个心形或两个半心形曲线。看起来心形被分开了!请帮我纠正合适的阴影选项。提前谢谢!我的代码
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\cur{(0,-2.7)..controls (-1.85,-1.45) and (-1.8,-0.52)..(-1.7,-0.13)
..controls (-1.52,0.63) and (-0.37,0.74)..(0,0)
..controls (0.37,0.74) and (1.52,0.63)..(1.7,-0.13)
..controls (1.8,-0.52) and (1.85,-1.45).. cycle};
\path[shading=ball,ball color=red] \cur;
\def\curh{(0,-2.7)..controls (-1.85,-1.45) and (-1.8,-0.52)..(-1.7,-0.13)
..controls (-1.52,0.63) and (-0.37,0.74)..(0,0)};
\begin{scope}[yshift=-3cm]
\path[shading=ball,ball color=red] \curh;
\path[shading=ball,ball color=red,xscale=-1] \curh;
\end{scope}
\end{tikzpicture}
\end{document}
根据建议,又一个版本。非常感谢大家的帮助!
\documentclass[tikz,border=2mm]{standalone}
\pgfdeclareradialshading{heart}{\pgfpoint{-0.45cm}{0.35cm}}%
{%
color(0cm)=(white!50!red);
color(0.25cm)=(red!90!black);
color(0.75cm)=(red!70!black);
color(1.5cm)=(red!60!black)
}
\pgfdeclareradialshading{heart2}{\pgfpoint{0.45cm}{0.35cm}}%
{%
color(0cm)=(white!50!red);
color(0.25cm)=(red!90!black);
color(0.75cm)=(red!70!black);
color(1.5cm)=(red!60!black)
}
\begin{document}
\begin{tikzpicture}
\pgfsetblendmode{lighten}
\def\cur{(0,-2.7)..controls (-1.85,-1.45) and (-1.8,-0.52)..(-1.7,-0.13)
..controls (-1.52,0.63) and (-0.37,0.74)..(0,0)
..controls (0.37,0.74) and (1.52,0.63)..(1.7,-0.13)
..controls (1.8,-0.52) and (1.85,-1.45).. cycle};
\draw[line width=2pt,red!60!black] \cur;
\path[shading=heart] \cur;
\path[shading=heart2] \cur;
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{fadings, patterns}
\begin{document}
\begin{tikzpicture}
\def\cur{(0,-2.7)..controls (-1.85,-1.45) and (-1.8,-0.52)..(-1.7,-0.13)
..controls (-1.52,0.63) and (-0.37,0.74)..(0,0)
..controls (0.37,0.74) and (1.52,0.63)..(1.7,-0.13)
..controls (1.8,-0.52) and (1.85,-1.45).. cycle};
\clip \cur;
\fill[top color=white, bottom color=red!80!black, middle color=red!75!black] (-2,-0.8) rectangle (2,0.5);
\fill[red!75!black, yshift=-0.5cm] \cur;
\fill[red!75!black, outer color=red!75!black, inner color=orange] (0,-1) circle[radius=0.8];
\fill[red!75!black, outer color=red!75!black, inner color=orange] (-1.6,-1.5) circle[radius=0.8];
\fill[red!75!black, outer color=red!75!black, inner color=white] (1.8,-1.5) circle[radius=1];
\draw[red!75!black, line width=8pt] \cur;
\end{tikzpicture}
\end{document}
答案2
这是一个起点。它需要一些调整。
我改变了圆弧和圆的路径,这样我就知道中心了。然后,这里的关键是制作一些阴影。它需要更多的阴影才能看起来像原始图片,正如我所说:一个起点。
编辑:lighten
添加混合模式稍微好一点(恕我直言) 。
这是我的代码:
\documentclass[tikz,border=2mm]{standalone}
\newcommand{\outerheart}
{(0,0) arc (30:210:1) to [out=-60,in=150] (0,-2.75) to [out=30,in=240] (-30:2) arc (-30:150:1)}
\newcommand{\innerheart}
{(210:0.1) arc (30:210:0.9) to [out=-60,in=150] (0,-2.65) to [out=30,in=240]
(-30:1.9) arc (-30:150:0.9) to [out=240,in=300] cycle}
\pgfdeclareradialshading{heart}{\pgfpoint{0cm}{0cm}}%
{%
color(0cm)=(yellow!50!red);
color(0.3cm)=(red!90!black);
color(0.6cm)=(red!70!black);
color(2cm)=(red!60!black)
}
\pgfdeclareverticalshading{shine}{2cm}%
{%
color(0cm)=(yellow!50!red);
color(1.6cm)=(red!70!black);
color(2cm)=(white)
}
\begin{document}
\begin{tikzpicture}
\pgfsetblendmode{lighten}
\begin{scope}
\clip\outerheart;
\fill[shading=heart] (0,-1) circle (2);
\end{scope}
\foreach\i in {210,330}
{
\begin{scope}[shift={(\i:1)}]
\clip (150:0.9) arc (150:30:0.9) to [out=140,in=40] cycle;
\fill[shading=shine] (0,0) circle (0.9);
\end{scope}
}
\fill[red!80!black,even odd rule]\outerheart\innerheart;
\end{tikzpicture}
\end{document}
输出结果如下:
答案3
您需要将两个路径合并为一个。例如:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\curh{(0,-2.7)..controls (-1.85,-1.45) and (-1.8,-0.52)..(-1.7,-0.13)
..controls (-1.52,0.63) and (-0.37,0.74)..(0,0)};
\path[shading=ball,ball color=red] \curh [xscale=-1] \curh;
\end{tikzpicture}
\end{document}
答案4
这只是为了展示如何用半颗心形来制作一颗完整的心形。只使用半条路径的问题在于,\draw
为了使它成为 的封闭路径\fill
,您不仅需要反射路径,还需要反转笔触。spath3
来拯救它:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{spath3}
\begin{document}
\begin{tikzpicture}
\def\curh{(0,-2.7)..controls (-1.85,-1.45) and (-1.8,-0.52)..(-1.7,-0.13)
..controls (-1.52,0.63) and (-0.37,0.74)..(0,0)};
\path[spath/save=apath] \curh;
\filldraw[
green,
draw=black,
ultra thick,
spath/use=apath
] [spath/transform={apath}{xscale=-1}, spath/use={apath, reverse, move, weld}] -- cycle;
\end{tikzpicture}
\end{document}