我想声明一个自定义形状
\radius \pgf@xa=\pgf@x
\centerpoint \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathcircle{\centerpoint}{\radius/10}
\pgfpathmoveto{\centerpoint}
\pgfpathellipse{\centerpoint}{\pgfpoint{\radius/2-\radius/10}{0}}{\pgfpoint{0}{\radius/10}}
\pgfpathellipse{\centerpoint}{\pgfpoint{\radius/2-\radius/10}{0}}{\pgfpoint{0}{\radius/10}}
自定义形状将继承自圆形。我有以下问题:
- 如何用给定的颜色填充圆形、椭圆形等?
- 我怎样才能将第一个半径为/2 的椭圆的中心点向左移动,将第二个半径为/2 的椭圆的中心点向右移动?
答案1
您需要对创建的路径进行描边、填充、阴影或剪切。这是一个快速模型(虽然有点太快了,但路径模式确实很老套。有更合适的方法可以做到这一点。只需查看形状库)。对于移动点,您可以使用\pgfpointadd
或\pgfpointdiff
等。
\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{circse}{
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\backgroundpath{
\radius
\pgf@xa=\pgf@x
\centerpoint \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathcircle{\centerpoint}{\radius/10}
%\pgfpathmoveto{\centerpoint}
\pgfpathellipse{\pgfpointadd{\centerpoint}{\pgfpoint{10pt}{0pt}}}{\pgfpoint{\radius/2-\radius/10}{0}}{\pgfpoint{0}{\radius/10}}
\pgfpathellipse{\pgfpointadd{\centerpoint}{\pgfpoint{-10pt}{0pt}}}{\pgfpoint{\radius/2-\radius/10}{0}}{\pgfpoint{0}{\radius/10}}
\begingroup
\tikz@mode
\iftikz@mode@fill
\iftikz@mode@draw
\pgfusepath{fill,draw}
\else
\pgfusepath{fill}
\fi
\else
\iftikz@mode@draw
\pgfusepath{draw}
\fi
\fi
\endgroup
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[circse,thick,draw=red,fill=yellow,scale=5] {};
\end{tikzpicture}
\end{document}