summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikzlings/tikzlings.sty
blob: ecd7562fb8760dadf86b1e05b5e5df11cf4beb87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
% !TeX root = ./examples/tikzlings.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This is the main part of the TikZlings package
% A package to bring cute little animals and other beings into tikz
% Maintained by samcarter
%
% Project repository and bug tracker:
% https://github.com/samcarter/tikzlings
%
% Released under the LaTeX Project Public License v1.3c or later
% See http://www.latex-project.org/lppl.txt
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{tikzlings}[2022/06/17 version v1.0 Collection of packages to draw animals and other beings in TikZ]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% List of all TikZlings
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{tikzlings-list}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% load sub-packages
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{tikz}

\ExplSyntaxOn
\cs_new_eq:NN \tikzlings@clistMapInlineNn \clist_map_inline:Nn
\ExplSyntaxOff

\tikzlings@clistMapInlineNn{\tikzlings@packages@clist}{%
  \RequirePackage{tikzlings-#1}}

\RequirePackage{tikzlings-addons}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Drawing a random tikzling
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{expl3}
\ExplSyntaxOn
\ifdefined\sys_rand_seed:
  \pgfmathsetseed {\sys_rand_seed:}
\else
  \ifdefined\pdfrandomseed % pdflatex
  \else
      \ifdefined\randomseed 
        \let\pdfrandomseed\randomseed % post TL19 xelatex and lualatex
      \else
          \let\pdfrandomseed\time % pre TL19 xelatex
      \fi
  \fi
  \pgfmathsetseed{\number\pdfrandomseed} 
\fi

% #1: tikzling name.
% The second argument of \__tikzlings_show_tikzling:nn will be provided
% by \tikzling.
\cs_new:Npn \__tikzlings_brace_item:n #1
  { { \__tikzlings_show_tikzling:nn {#1} } }

% #1: tikzling name
% #2: options passed to its command
\cs_new_protected:Npn \__tikzlings_show_tikzling:nn #1#2
  {
    \group_begin:
      \pgfkeys
        {
          /#1/.search~also/.expanded =
            { /tikz, /pgf, /thing, \tikzlings@search@paths@clist }
        }
      \use:c {#1} [{#2}]
    \group_end:
  }

\cs_new_protected:Npn \__tikzlings_declare_pgfmath_random_list:n #1
  {
    \pgfmathdeclarerandomlist { tikzlings } {#1}
  }

% Variant that uses \edef on the argument, then passes the result to
% \__tikzlings_declare_pgfmath_random_list:n
\cs_generate_variant:Nn \__tikzlings_declare_pgfmath_random_list:n { x }

% Works because \clist_map_function:NN is expandable
\__tikzlings_declare_pgfmath_random_list:x
  {
    \clist_map_function:NN \g__tikzlings_names_clist \__tikzlings_brace_item:n
  }
\ExplSyntaxOff

\newcommand{\tikzling}[1][]{%
  \pgfmathrandomitem{\tikzlings@random}{tikzlings}%
  % #1 is passed as second argument to \__tikzlings_show_tikzling:nn
  \tikzlings@random{#1}%
}