Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
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 Apr 26 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 Apr 26 at 9:40
1  
@Ignasi Thank you it works, feel free to make answer, I'll accept it. –  Tarass Apr 26 at 10:14
    
@percusse you're right, I missplaced the args stuff. Thank's. –  Tarass Apr 26 at 10:35

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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