%D \module
%D   [       file=meta-tab,
%D        version=2003.03.21, % very old but now with splitter
%D          title=\METAPOST\ Graphics,
%D       subtitle=Dummy (External) Graphics,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\startuseMPgraphic{TallyBar}
    height := (10/12) * LineHeight ;
    span   := ( 4/10) * LineHeight ;
    drift  := ( 1/10) * LineHeight ;
    def d = (uniformdeviate drift) enddef ;
    for i := 1 upto \MPvar{n} :
        draw
            if (i mod 5)=0 :
                ((-d-4.5span,d)--(+d-0.5span,height-d))
            else :
                ((-d,+d)--(+d,height-d))
            fi
            shifted (span*i,d-drift) withpen pencircle ;
    endfor ;
    currentpicture := currentpicture scaled .75 ;
\stopuseMPgraphic

\setupMPvariables
  [TallyBar]
  [n=0]

\unexpanded\def\tallynumeral#1%
  {\dontleavehmode
   \lower.25\exheight\hpack{\useMPgraphic{TallyBar}{n=#1}}}

\unexpanded\def\tallynumerals#1%
  {\dontleavehmode
   \begingroup
   \scratchcounter#1\relax
   \doloop
     {\ifnum\scratchcounter>\plusfive
        \lower.25\exheight\hpack{\useMPgraphic{TallyBar}{n=5}}%
        \advance\scratchcounter-\plusfive
        \space
      \else
        \lower.25\exheight\hpack{\useMPgraphic{TallyBar}{n=\the\scratchcounter}}%
        \exitloop
      \fi}%
   \endgroup}

\let\FunnyBar\tallynumeral

\defineconversion[tally][\tallynumerals]

\continueifinputfile{meta-imp-tab.mkiv}

\starttext

    \starttabulate[|pr|c|]
        \NC \tallynumerals {24} \NC        \NR
        \NC \tallynumerals {12} \NC \times \NR
        \HL
        \NC \tallynumerals{288} \NC      = \NR
    \stoptabulate

    \tallynumerals{"FFFF}

\stoptext

\endinput

