18

My question is related to Wind power and tikz force.

Thanks to Mark Wibrow I have some nice wind turbines, but I want to scale them and make some dynamic changes. I try to had some new parameters, but it doesn' work. I just add to his original code:

  \tikzset{path/.style args={#1 scale #2}{fill, draw=white, ultra thick, line join=round}}
  \begin{scope}[scale=#2]
  \path [path] 
(-.25,0) arc (180:360:.25 and .0625) -- (.0625,3) -- (-.0625,3) -- cycle;
  ...
  \end{scope}

and

It's not working:

<argument> ...set {path/.style args={##1 scale ##2
                                              }{fill, draw=white, ultra ...
l.418 }}

Edit Solved thanks to Ignasi:

enter image description here

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc}

\tikzset{
    pics/mysymbol/.style args={#1 scale #2 with #3}{
        code={
    \tikzset{WinT/.style={%
                fill,draw=white,line join=round,#3}}
    \begin{scope}[scale=#2]
    \path[WinT] (-.25,0) arc (180:360:.25 and .0625)
        -- (.0625,3) -- (-.0625,3) -- cycle;
    \pgfmathsetmacro{\Rand}{(rand*60 + 1) - 30}
    \foreach \i in {90, 210, 330}{
    \ifcase#1
    \or
        \path [WinT, shift=(90:3), rotate=\i+\Rand] 
        (.5,-.1875) arc (270:90:.5 and .1875)
        arc (90:-90:1.5 and .1875);
    \or
        \path [WinT, shift=(90:3), rotate=\i+\Rand] 
        (0,0.125) -- (2,0.125) -- (2,0) -- (0.5,-0.375) -- cycle;
    \or
        \path [WinT, shift=(90:3), rotate=\i+\Rand]
        (0,-0.125) arc (180:0:1 and 0.125) -- ++(0,0.125)
        arc (0:180:1 and 0.25) -- cycle;
    \fi
    }
    \path [WinT] (0,3) circle [radius=.25];
    \end{scope}
}}}

\begin{document}
\begin{tikzpicture}[scale=0.4]
\draw[help lines] (0,-2) grid (20,20) ;

\draw[fill=blue!50, opacity=.5] (1,0) arc (180:90:18) -- ++(0,-2)
    arc (90:180:16) --cycle ;

\draw[<->,>=stealth,thick] (1,-1)--(3,-1) node[midway,below]
        {\scriptsize 200\,m} ;

\foreach \i in {13,12,...,0} {%
    \begin{scope}[shift={($(19,0) + (176-\i*6.35:16.9)$)}]
    \path (0,0) pic {mysymbol={1 scale .25 with thick}} ;
    \end{scope}
    }

\end{tikzpicture}\end{document}
3
  • 1
    I'm not sure because you don't show the initial code but when pics with parameters are declared, a special declaration is needed. Instead of wind turbine/.pic you must use pics/wind turbine/.style={code={... An example: How to create something like a function (procedure, macros, etc.) in TikZ?
    – Ignasi
    Commented Apr 26, 2014 at 9:08
  • 2
    path style requires arguments but you are not providing any in the required form such as path=1 scale 2
    – percusse
    Commented Apr 26, 2014 at 9:40
  • @percusse you're right, I missplaced the args stuff. Thank's.
    – Tarass
    Commented Apr 26, 2014 at 10:35

1 Answer 1

13

TikZ documentation explains (section 18.3) that pics are defined with syntax

\tikzset{
   pics/picname/.style={
       code={
            <pic commands>},
   }
}

although key handler .pic is provided to allow an alternative and easier version

\tikzset{    
    picname/.pic={ 
       <pic commands> },
}

But TikZ documentation also says:

In almost all cases, the .pic key handler will suffice to setup keys. However, there are cases where you really need to use the first version using .style and code=:

  • Whenever your pic type needs to set the foreground or the background code.
  • In case of complicated arguments given to the keys.

Therefore, you must change your wind turbine declaration to use first (complete) syntax to pass complicated arguments.

0

You must log in to answer this question.

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