使用 TikZ 绘制玛雅数字

使用 TikZ 绘制玛雅数字

我正在寻找一种绘画方法玛雅数字使用 TikZ。我想要一个宏\maya{21},它能给我提供玛雅数字系统中数字 21 的图形表示。

有包mathabx提供类似的东西。但我不能使用它,因为我正在使用mnsymbol并且存在一些兼容性问题。

下图显示了玛雅系统中每个数字的符号:

玛雅数字系统

梅威瑟:

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}

\begin{document}
  How to do it?
\end{document}

答案1

您可以从文档中复制相关代码mathabx.sty并将其复制mathabx.dcl到文档中。

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnta%
\newcount\mayacntc%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

的定义\mayaexpansion已相应改变answer沃纳 (Werner) 有正确的旋转数字(需要graphicx)。

因此,使用命令\mayadigit{<number>}你可以获得你想要的东西,就像下面的 MWE 一样

\documentclass{article}
\usepackage{graphicx,MnSymbol}

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnta%
\newcount\mayacntc%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

\begin{document}

$\mayadigit{0}\quad\mayadigit{9}\quad\mayadigit{19}$

\end{document} 

得出

在此处输入图片描述


编辑

我并不是玛雅数字方面的专家……

尝试用下面的代码替换上面的代码以获得>20的数字:

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnter%
\newcount\mayacnta%
\newcount\mayacntb%
\newcount\mayacntc%
\newdimen\mayawidth%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayarecurse{{%
    \mayacnta=\mayacnter \divide\mayacnter by 20
    \ifnum\mayacnter>0\mayarecurse\fi
    \mayacntb=\mayacnter
    \multiply\mayacntb by-20
    \advance\mayacnta by\mayacntb
    \hbox to\mayawidth{\hss\mayaexpansion\hss}}}%
%
\def\maya#1{%
    \mayacnter=#1
    \setbox0\hbox{\mathbfont 0}%
    \mayawidth=\wd0
    \left.
    \vcenter{\mayarecurse}
    \right.}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

并使用命令\maya{<number>}代替\mayadigit{<number>},如以下 MWE 所示:

\documentclass{article}
\usepackage{graphicx,MnSymbol}

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnter%
\newcount\mayacnta%
\newcount\mayacntb%
\newcount\mayacntc%
\newdimen\mayawidth%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayarecurse{{%
    \mayacnta=\mayacnter \divide\mayacnter by 20
    \ifnum\mayacnter>0\mayarecurse\fi
    \mayacntb=\mayacnter
    \multiply\mayacntb by-20
    \advance\mayacnta by\mayacntb
    \hbox to\mayawidth{\hss\mayaexpansion\hss}}}%
%
\def\maya#1{%
    \mayacnter=#1
    \setbox0\hbox{\mathbfont 0}%
    \mayawidth=\wd0
    \left.
    \vcenter{\mayarecurse}
    \right.}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

\begin{document}

$\maya{0}\quad\maya{9}\quad\maya{19}\quad\maya{49}$

\end{document} 

结果:

在此处输入图片描述

答案2

思考这样做:

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}

\newcount\mayannumber
\newcount\mayantmpa
\newcount\mayantmpb

\newcommand\mayan[2][]{%
\begin{scope}[#1,scale=1/4]%
    \mayannumber=#2\relax%
    \mayantmpb=20\relax
    \pgfmathloop
        \mayantmpa=\mayannumber
        \advance\mayantmpa by-\mayantmpb
        \ifnum\mayantmpa<0
        \else
        \multiply\mayantmpb by20
    \repeatpgfmathloop
    %
    \divide\mayantmpb by20\relax
    \tikzset{shift=(90:\pgfmathcounter*5-5)}
    \pgfmathloop
        \ifnum\mayantmpb=0
        \else
        \mayantmpa=\mayannumber\relax
        \divide\mayantmpa by\mayantmpb\relax
        {%
          \pgfmathloop%
          \ifnum5>\mayantmpa
            \ifnum0<\mayantmpa
              \foreach \i in {1,...,\mayantmpa}
                % Dot.
                  \fill (\i -\the\mayantmpa/2-1/2,1/4) circle [radius=1/4];
            \else%
              \ifnum\mayantmpa=\mayannumber
                % Shell
                \draw [thick, scale=5/4, shift=(90:2/3), line cap=round] 
                  (-60:1 and 2/3) 
                  \foreach \i in {-30,0,...,240}{ to [bend right, looseness=1.5] (\i:1 and 2/3)}
                  \foreach \i in {-60, -30,0,...,240}{ (0,-2/3) -- (\i:1 and 2/3)};
              \fi
           \fi
          \else%
            % Bar
            \fill (-2,0) rectangle (2,1/2);
            \tikzset{shift={(0,1)}}
            \advance\mayantmpa by-5
          \repeatpgfmathloop    
        }%
        \multiply\mayantmpa by\mayantmpb\relax
        \advance\mayannumber by-\mayantmpa
        \divide\mayantmpb by20
        \ifnum0<\mayantmpb
        \tikzset{shift={(0,-5)}}
        \path (-2,0) rectangle (2,1/2); % to enlarge bounding box
        \fi
    \repeatpgfmathloop
\end{scope}%
}
\begin{document}
%

\begin{tikzpicture}

\foreach \n [count=\i from 0, evaluate={\x=mod(\i, 5)/8*9; \y=int(\i/5)/8*12;}] in {0,...,19}{
 \mayan[shift={(\x,\y)}]{\n}
 \node [below] at (\x,\y) {\n};
}

\foreach \n [count=\i from 0, evaluate={\x=mod(\i, 5)/8*9; \y=-int(\i/5)/8*12-4;}] in {33, 56, 400, 429, 5425}{
 \mayan[shift={(\x,\y)}]{\n}
 \node [below] at (\x,\y) {\n};
}

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

只是为了好玩而使用 PGF。

代码

\documentclass[varwidth]{standalone}
\usepackage{pgf}
\makeatletter
\newcommand*\mayanumber[2][]{%
 \pgfpicture[#1]
  \pgftransformyscale{-1}
  \pgfmathdectobase\maya@{#2}{20}
  \expandafter\pgfutil@tfor\expandafter\maya@\expandafter:\expandafter=\maya@\do{
   \if0\maya@
     \maya@shell
     \pgftransformyshift{.5*(\pgfkeysvalueof{/pgf/maya digitty yshift})}
   \else
     \pgfmathbasetobase{\maya@}{\maya@}{20}{5}
     \expandafter\maya@number\maya@\@@
   \fi
   \pgftransformyshift{\pgfkeysvalueof{/pgf/maya digit yshift}}}
 \endpgfpicture}
\newcommand*\maya@shell{\pgfscope
  \pgfpathellipse{\pgfpointscale{.5}{\pgfpoint{\pgfkeysvalueof{/pgf/maya bar width}}{\pgfkeysvalueof{/pgf/maya bar height}}}}
    {\pgfpoint{.5*(\pgfkeysvalueof{/pgf/maya bar width})}{+0pt}}{\pgfpoint{+0pt}{\pgfkeysvalueof{/pgf/maya bar height}}}
  \pgfusepath{clip,stroke}%
  \pgfsetlinewidth{.5\pgflinewidth}
  \pgfutil@for\maya@@:=.2,.4,.6,.8\do{
    \pgfpathmoveto{\pgfpoint{\maya@@*(\pgfkeysvalueof{/pgf/maya bar width})}{-(\pgfkeysvalueof{/pgf/maya bar height})}}
    \pgfpathlineto{\pgfpoint{\maya@@*(\pgfkeysvalueof{/pgf/maya bar width})}{2*(\pgfkeysvalueof{/pgf/maya bar height})}}
    \pgfusepath{stroke}
  }\endpgfscope}
\def\maya@number#1#2\@@{%
  \def\pgf@temp{#2}%
  \ifx\pgf@temp\pgfutil@empty\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi
    {\maya@number0#1\@@}
    {\begingroup\pgftransformxshift{.5*(\pgfkeysvalueof{/pgf/maya bar width})}
        \pgftransformxshift{-.5*(#2-1)*(\pgfkeysvalueof{/pgf/maya bar height}+\pgfkeysvalueof{/pgf/maya circle seps})}
        \pgfmathloop\ifnum\pgfmathcounter>#2\else
          \pgfpathcircle{\pgfpoint{+0pt}{.5*(\pgfkeysvalueof{/pgf/maya bar height})}}{.5*(\pgfkeysvalueof{/pgf/maya bar height})}
          \pgfusepath{fill}
          \pgftransformxshift{\pgfkeysvalueof{/pgf/maya bar height}+\pgfkeysvalueof{/pgf/maya circle seps}}
        \repeatpgfmathloop
       \endgroup
      \pgfmathloop\ifnum\pgfmathcounter>#1\else
        \pgftransformyshift{\pgfkeysvalueof{/pgf/maya digitty yshift}}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\pgfkeysvalueof{/pgf/maya bar width}}{\pgfkeysvalueof{/pgf/maya bar height}}}
        \pgfusepath{fill}
      \repeatpgfmathloop}}
\pgfset{%
  maya digit yshift/.initial  =+.2em,
  maya digitty yshift/.initial=+.11em,
  maya bar height/.initial    =+.09em,
  maya bar width/.initial     =+.5em,
  maya circle seps/.initial   =+.03em}
\makeatother
\begin{document}
\begin{tabular}{rc}
  33 & \mayanumber{33}   \\
 429 & \mayanumber{429}  \\
2000 & \mayanumber{2000} \\
5125 & \mayanumber{5125}
\end{tabular}
\end{document}

输出

在此处输入图片描述

相关内容