diff options
author | Karl Berry <karl@freefriends.org> | 2022-08-14 20:27:47 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-08-14 20:27:47 +0000 |
commit | 877588f3a4ffc33328e9acf568a7eef502f5f768 (patch) | |
tree | 0e83de2e15c3a6dedc0d55738979ea1a59c26322 /Master/texmf-dist/tex | |
parent | e8eab1499a1580923a76e92453fe80dc2459538d (diff) |
nimsticks (14aug22)
git-svn-id: svn://tug.org/texlive/trunk@64118 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/nimsticks/nimsticks.sty | 94 |
1 files changed, 68 insertions, 26 deletions
diff --git a/Master/texmf-dist/tex/latex/nimsticks/nimsticks.sty b/Master/texmf-dist/tex/latex/nimsticks/nimsticks.sty index c21b2758462..bd80b226ded 100644 --- a/Master/texmf-dist/tex/latex/nimsticks/nimsticks.sty +++ b/Master/texmf-dist/tex/latex/nimsticks/nimsticks.sty @@ -5,7 +5,7 @@ %% The original source files were: %% %% nimsticks.dtx (with options: `nimsticks') -%% Copyright (c) 2020 Peter Rowlett +%% Copyright (c) 2022 Peter Rowlett %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ %% SOFTWARE. %% -\ProvidesPackage{nimsticks}[2022/08/09 nimsticks 1.2] +\ProvidesPackage{nimsticks}[2022/08/14 nimsticks 2.0.1] \RequirePackage[first=-100,last=100,seed=0]{lcg} \RequirePackage{tikz} \RequirePackage{etoolbox} @@ -36,38 +36,80 @@ {\PackageWarning{nimsticks}{Command `nimgame' already defined}} \@ifundefined{listofgames}{} {\PackageWarning{nimsticks}{Command `listofgames' already defined}} -\@ifundefined{c@topx}{} - {\PackageWarning{nimsticks}{Counter `topx' already defined}} +\@ifundefined{nimstickcolour}{} + {\PackageWarning{nimsticks}{Command `nimstickcolour' already defined}} +\@ifundefined{setnimstickcolour}{} + {\PackageWarning{nimsticks}{Command `setnimstickcolour' already defined}} +\@ifundefined{nimstickheight}{} + {\PackageWarning{nimsticks}{Command `nimstickheight' already defined}} +\@ifundefined{nimstickthickness}{} + {\PackageWarning{nimsticks}{Command `nimstickthickness' already defined}} +\@ifundefined{nimstickgap}{} + {\PackageWarning{nimsticks}{Command `nimstickgap' already defined}} +\@ifundefined{nimheapgap}{} + {\PackageWarning{nimsticks}{Command `nimheapgap' already defined}} +\@ifundefined{nimheapwobble}{} + {\PackageWarning{nimsticks}{Command `nimheapwobble' already defined}} +\@ifundefined{nimheaplift}{} + {\PackageWarning{nimsticks}{Command `nimheaplift' already defined}} +\@ifundefined{nimrandrange}{} + {\PackageWarning{nimsticks}{Command `nimrandrange' already defined}} +\@ifundefined{setnimscale}{} + {\PackageWarning{nimsticks}{Command `setnimscale' already defined}} +\@ifundefined{onenimstick}{} + {\PackageWarning{nimsticks}{Command `onenimstick' already defined}} \@ifundefined{topx}{} - {\PackageWarning{nimsticks}{Existing command `topx' conflicts with counter `topx'}} -\@ifundefined{c@botx}{} - {\PackageWarning{nimsticks}{Counter `botx' already defined}} + {\PackageWarning{nimsticks}{Command `topx' already defined}} \@ifundefined{botx}{} - {\PackageWarning{nimsticks}{Existing command `botx' conflicts with counter `botx'}} -\@ifundefined{c@heap}{} - {\PackageWarning{nimsticks}{Counter `heap' already defined}} + {\PackageWarning{nimsticks}{Command `botx' already defined}} +\@ifundefined{lift}{} + {\PackageWarning{nimsticks}{Command `lift' already defined}} \@ifundefined{heap}{} - {\PackageWarning{nimsticks}{Existing command `heap' conflicts with counter `heap'}} -\@ifundefined{c@heapindex}{} - {\PackageWarning{nimsticks}{Counter `heapindex' already defined}} + {\PackageWarning{nimsticks}{Command `heap' already defined}} \@ifundefined{heapindex}{} - {\PackageWarning{nimsticks}{Existing command `heapindex' conflicts with counter `heapindex'}} + {\PackageWarning{nimsticks}{Command `heapindex' already defined}} + +\newcommand{\nimstickcolour}{black} +\newcommand{\setnimstickcolour}[1]{% + \renewcommand{\nimstickcolour}{#1} +} + +\newcommand{\nimstickheight}{3.3} % in ex +\newcommand{\nimstickthickness}{0.3} % in ex +\newcommand{\nimstickgap}{0.3} % in ex +\newcommand{\nimheapgap}{5} % in ex +\newcommand{\nimheapwobble}{0.001} % in ex +\newcommand{\nimheaplift}{0.002} % in ex +\newcommand{\nimrandrange}{100} +\newcommand{\setnimscale}[1]{% + \pgfmathsetmacro{\nimstickheight}{3.3*#1}% + \pgfmathsetmacro{\nimstickthickness}{0.3*#1}% + \pgfmathsetmacro{\nimstickgap}{0.3*#1^(0.5)}% + \pgfmathsetmacro{\nimheapgap}{5*#1^(0.25)}% + \pgfmathsetmacro{\nimheapwobble}{0.001*#1^(0.25)}% + \pgfmathsetmacro{\nimheaplift}{0.002*#1}% + \pgfmathtruncatemacro{\nimrandrange}{100*#1}\reinitrand[first=-\nimrandrange,last=\nimrandrange,seed=0]% +} + +\newcommand{\onenimstick}{\draw[line width=\nimstickthickness ex,\nimstickcolour] (\topx,0ex) -- (\botx,\nimstickheight ex);} \newcommand{\drawnimstick}{% - \rand\pgfmathsetmacro{\topx}{(\the\value{rand})/1000}% - \rand\pgfmathsetmacro{\botx}{(\the\value{rand})/1000}% - \begin{tikzpicture}% - \draw[very thick] (\topx,0) -- (\botx,0.5);% + \rand\pgfmathsetmacro{\topx}{(\the\value{rand})*\nimheapwobble}% + \rand\pgfmathsetmacro{\botx}{(\the\value{rand})*\nimheapwobble}% + \rand\pgfmathsetmacro{\lift}{(\nimrandrange+\the\value{rand})*\nimheaplift}% + \begin{tikzpicture} + \node[inner sep=0] at (0,0) {}; % to anchor the diagram so any random movement isn't recentred + \onenimstick \end{tikzpicture}% } \newcommand{\nimgame}[2][block]{% - \ifstrequal{#1}{inline}{}{\bgroup\centering}% - \def\listofgames{#2}% - \foreach \heap in \listofgames {% - \foreach \heapindex in {1, ..., \heap} {% - \drawnimstick\hspace{0.5mm}% - }% - \hspace{10mm}% - }\hspace{-10mm}% + \ifstrequal{#1}{inline}{}{\par\bgroup\centering}% + \def\listofgames{#2}% + \foreach \heap in \listofgames {% + \foreach \heapindex in {1, ..., \heap} {% + \drawnimstick\hspace{\nimstickgap ex}% + }% + \hspace{\nimheapgap ex}% + }\hspace{-\nimheapgap ex}% \ifstrequal{#1}{inline}{}{\par\egroup}% } \endinput |