5

I'd like to create a key shape symbol using PSTricks, but I have some problems filling it...

Here's the shape I'd like :

\documentclass[pstricks, float]{standalone}
usepackage[table, usenames, dvipsnames]{xcolor}
\usepackage{pstricks, pst-node, pst-circ, pst-plot,
    pst-3dplot,pst-solides3d, pst-sigsys, pstricks-add,pst-eucl}


\begin{document}
\begin{pspicture}[labelangle=:U, showgrid=true](-3, -3)(5, 3)
    \pscustom[fillstyle=solid, fillcolor=green]{
        \psarc[]{-}(0.2, 0){0.8}{25}{346}     % Exterior disk
        \pscircle[linewidth=2pt](0, 0){0.25}  % Hole

        \psline[]{-}(0.9250, 0.3380)(3, 0.3380)(3.3, 0)(3, -0.3420)(2.8, -0.3420)
        (2.8, -0.3420)(2.65, -0.1920)(2.55, -0.3420)(2.45, -0.1920)(2.25, -0.4920)
        (2.15, -0.3420)(2.05, -0.4920)(1.95, -0.3420)(1.85, -0.4920)(1.65, -0.1920)
        (1.55, -0.3420)(1.45, -0.1920)(1.25, -0.4920)(1.05, -0.1935)(0.9762, -0.1935)
    }   
\end{pspicture}
\end{document}

But the pscustom doesn't work as expected.

Here's the result :

MWE result

I have thus two problems :

  1. Create a closed shape with the \psarc and the \psline
  2. Scoop the \pscircle out of the shape

I haven't find the commands in the user's manual that allows me to do so, and I hope I'm wrong...

Besides, that I'd like to turn the key shape into a new PS object, let's say a \psKey, that could be filled, linestyle-d, and so on... I know it's about the \makeatletter and \makeatother but I could get proper results...

Is this structure wrong ? Should I save it as psKey.tex ?

\makeatletter
\def\tor(#1){%
    \rput(#1){%
        %
        % Code lines of the key drawing
        %
        }
    }
\makeatother

3 Answers 3

6
\documentclass[pstricks]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}[showgrid=true](-3, -3)(5, 3)
    \pscustom[fillstyle=solid, fillcolor=green]{
       \psarcn(0.2, 0){0.8}{346}{25}     % Exterior disk
        \psline(3, 0.3380)(3.3, 0)(3, -0.3420)(2.8, -0.3420)
        (2.8, -0.3420)(2.65, -0.1920)(2.55, -0.3420)(2.45, -0.1920)(2.25, -0.4920)
        (2.15, -0.3420)(2.05, -0.4920)(1.95, -0.3420)(1.85, -0.4920)(1.65, -0.1920)
        (1.55, -0.3420)(1.45, -0.1920)(1.25, -0.4920)(1.05, -0.1935)(0.9762, -0.1935)
        \pscircle[linewidth=2pt](0, 0){0.25}  % Hole
     }   
\end{pspicture}
\end{document}

enter image description here

For creating a new macro for this look into pstricks-add there you'll find a lot of examples, like this one:

\documentclass[pstricks]{standalone}
\usepackage{pstricks-add}

\makeatletter
\def\pstKey{\pst@object{pstKey}}
\def\pstKey@i{\@ifnextchar({\pstKey@ii{0}}\pstKey@ii}
\def\pstKey@ii#1(#2){%
  \addbefore@par{fillstyle=solid, fillcolor=green}%
  \begingroup
  \use@par
  \rput{#1}(#2){%
    \pscustom{
       \psarcn(0.2, 0){0.8}{346}{25}     % Exterior disk
        \psline(3, 0.3380)(3.3, 0)(3, -0.3420)(2.8, -0.3420)
        (2.8, -0.3420)(2.65, -0.1920)(2.55, -0.3420)(2.45, -0.1920)(2.25, -0.4920)
        (2.15, -0.3420)(2.05, -0.4920)(1.95, -0.3420)(1.85, -0.4920)(1.65, -0.1920)
        (1.55, -0.3420)(1.45, -0.1920)(1.25, -0.4920)(1.05, -0.1935)(0.9762, -0.1935)
        \pscircle[linewidth=2pt](0, 0){0.25}  % Hole
     }}%   
  \endgroup\ignorespaces
}
\makeatother

\begin{document}
\begin{pspicture}[showgrid=true](-3, -3)(5, 3)
\pstKey(0,0)
\pstKey[fillcolor=red,opacity=0.5]{90}(2,-2)
\end{pspicture}
\end{document}

enter image description here

And with a scaling option:

\documentclass[pstricks]{standalone}
\usepackage{pstricks-add}

\makeatletter
\def\pstKey{\pst@object{pstKey}}
\def\pstKey@i{\@ifnextchar({\pstKey@ii{0}}\pstKey@ii}
\def\pstKey@ii#1(#2){%
  \addbefore@par{fillstyle=solid, fillcolor=green}%
  \begingroup
  \use@par
  \rput{#1}(#2){\psscalebox{\psk@psscale}{%
    \pscustom{
       \psarcn(0.2, 0){0.8}{346}{25}     % Exterior disk
        \psline(3, 0.3380)(3.3, 0)(3, -0.3420)(2.8, -0.3420)
        (2.8, -0.3420)(2.65, -0.1920)(2.55, -0.3420)(2.45, -0.1920)(2.25, -0.4920)
        (2.15, -0.3420)(2.05, -0.4920)(1.95, -0.3420)(1.85, -0.4920)(1.65, -0.1920)
        (1.55, -0.3420)(1.45, -0.1920)(1.25, -0.4920)(1.05, -0.1935)(0.9762, -0.1935)
        \pscircle[linewidth=2pt](0, 0){0.25}  % Hole
     }}}%
  \endgroup\ignorespaces
}
\makeatother

\begin{document}
\begin{pspicture}[bgcolor=yellow!30](-3, -3)(5, 3)
\pstKey(0,0)
\pstKey[fillcolor=red,psscale=0.5,opacity=0.5]{90}(2,-1)
\end{pspicture}
\end{document}

enter image description here

10
  • Awesome, thanks ! And How can I turn this marvel into a symbol ?
    – 3isenHeim
    Sep 23, 2015 at 12:20
  • 1
    as I already wrote, have a look into pst-platon or pst-fractal. There are a lot of examples.
    – user2478
    Sep 23, 2015 at 12:50
  • OK, thanks. Actually, I though you quoted pstricks-add for the \pscustom, not for the symbol. Sorry for the misunderstanding.
    – 3isenHeim
    Sep 23, 2015 at 13:13
  • 1
    see edited answer
    – user2478
    Sep 23, 2015 at 14:23
  • 1
    \addbefore@par{...,linestyle=solid,linearc=0}
    – user2478
    Sep 23, 2015 at 16:10
1

The trick is to add the inner circle outside the \pscustom.

I defined a \pstKey command through several lists of empty nodes, so as to ease the modification of parameters. pstKey can be placed anywhere and rotated, with \rput.

\documentclass[float]{standalone}%
\PassOptionsToPackage{table, dvipsnames, x11names}{xcolor}
\usepackage{pstricks-add, pst-circ, pst-3dplot, pst-solides3d,pst-eucl}%, pst-sigsys

\usepackage{auto-pst-pdf}

\newcommand\pstKey{\pnodes{U}(3.3, 0)(3, 0.3380)(0.9250, 0.3380)%
\pnodes{b}(0.9762, -0.1935)(1.05, -0.1935)(1.45, -0.1920)(1.65, -0.1920)(2.45, -0.1920)(2.65, -0.1920)
\pnodes{m}(1.55, -0.3420)(1.95, -0.3420)(2.15, -0.3420)(2.55, -0.3420)(2.8, -0.3420)(3, -0.3420)
\pnodes{B}(1.25, -0.4920)(1.85, -0.4920)(2.05, -0.4920)(2.25, -0.4920)
%
\pscustom[fillstyle=solid, fillcolor=Gold4!40! HoneyDew4, opacity =0.65, linejoin =1]{%
\psline(U0)(U1)(U2)
 \psarc(0.2, 0){0.8}{25}{346} % Exterior disk
\psline(b0)(b1)(B0)(b2)(m0)(b3)(B1)(m1)(B2)(m2)(B3)(b4)(m3)(b5)(m4)(m5)(U0)
  }
  \pscircle[linewidth=2pt, fillstyle=solid, fillcolor=white](0, 0){0.25}% Hole
  }%

\begin{document}

\begin{pspicture}[labelangle=:U, showgrid=true](-3, -3)(5, 3)%
    \rput{-30}(1,1){\pstKey}
\end{pspicture}

\end{document} 

enter image description here

2
  • 1
    change the background color and the inner circle will still be filled with white instead of the background.
    – user2478
    Sep 23, 2015 at 14:29
  • That's what I did first and it didn't work. I guess I mixed up in various modifications of the O.P.'s code. Thank you, Herbert!
    – Bernard
    Sep 23, 2015 at 14:39
0

List of changes:

  • replace the last point with \closepath to fix the discontinuity at that point (it is noticeable for thick linewidth).
  • move linewidth=2pt to pscustom as linewidth declared inside pscustom does not take any effect.
  • remove the center of the last circle.
  • use 2 decimal points for literal numbers.
  • remove unnecessary pstricks-add.
  • reduce the canvas size.
\documentclass[pstricks]{standalone}
\begin{document}
\begin{pspicture}[showgrid=true](-1,-1)(4, 1)
    \pscustom[fillstyle=solid,fillcolor=green,linewidth=2pt]{
       \psarcn(0.2,0){0.8}{346}{25}
        \psline(3,0.33)(3.3,0)(3,-0.34)(2.8,-0.34)
                    (2.8,-0.34)(2.65,-0.19)(2.55,-0.34)(2.45,-0.19)(2.25,-0.49)
                    (2.15,-0.34)(2.05,-0.49)(1.95,-0.34)(1.85,-0.49)(1.65,-0.19)
                    (1.55,-0.34)(1.45,-0.19)(1.25,-0.49)(1.05,-0.19)%(0.9762,-0.1935)
        \closepath
        \pscircle{0.25}
     }   
\end{pspicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .