3

I would like to declare a custom shape

\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}}

The custom shape will inherit from circle. I have the following questions:

  1. How can I fill the circle,ellipse etc with the given color?
  2. How can I shift the center point of the first ellipse with radius/2 left and the second radius/2 right?
  • Is this a TikZ or a PGF question? Do you know of the ellipse shape from the shapes.geometric library that also includes a proper anchor border? What do you want to achieve? – Qrrbrbirlbel Oct 15 '13 at 22:55
5

You need to stroke or fill or shade or clip the path you have created. Here is a quick mock-up (though it's a little too quick, the path modes are really hacky. There are more proper ways of doing it. Just check the shapes library). For shifting points you can use \pgfpointadd or \pgfpointdiff etc.

\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}

enter image description here

  • 1
    Eh … The backgroundpath (and the foreground path) will be supplied with the options in \pgfnode{<shape>}{<anchor>}{<text>}{<name>}{<This will be executed after the background and the foreground path have been constructed.>}. Just do the path there and let TikZ/PGF do the rest. (It will add \begingroup\tikz@finish.) – Qrrbrbirlbel Oct 15 '13 at 22:53
  • 2
    @Qrrbrbirlbel I know it's just hack for making an example. – percusse Oct 15 '13 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.