%%
%% This is file `pst-soroban.sty',
%% 
%%% ====================================================================
%%% @LaTeX-file{
%%%   filename  = "pst-soroban.sty",
%%%   version   = "1.0",
%%%   date      = "2007/10/12",
%%%   author    = "Alain Delmotte",
%%%   address   = "Alain Delmotte,
%%%                avenue du Marathon, 6,
%%%                B-1348 Louvain-la-Neuve
%%%                BELGIUM",
%%%   email     = "esperanto@swing.be",
%%%   codetable = "ISO/ASCII",
%%%   keywords  = "soroban, abacus, japanese",
%%%   supported = "yes",
%%% }
%% This file can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%%
%

\RequirePackage{pstricks-add}
\RequirePackage{calc,ifthen}

\definecolor{brun}{rgb}{.6 .3 0}%{cmyk}{.4 .7 .7 0}
\newcommand{\colbil}{yellow}
\newcommand{\coltig}{brun}

\newcounter{xx}
\newcounter{yy}
\psset{unit=1mm}

\newcommand{\bille}[2]{\pspolygon[fillstyle=solid, fillcolor=#2, linecolor=\coltig, linewidth=0.6, linearc=0.2, origin={#1}](-8.7,0)(-2.2,5.3)(2.2,5.3)(8.7,0)(2.2,-5.3)(-2.2,-5.3)
\psline[linecolor=\coltig, linewidth=0.6, origin={#1}]{c-c}(-8.6,0)(8.6,0)
}

\newcommand{\support}[1]{%
\psline[linewidth=3.9, linecolor=\coltig](#1,-0.2)(#1,74)
\psline[linewidth=3.9, linecolor=white, origin={#1,0}](-11.2,54.4)(11.2,54.4)
\psline[linewidth=0.6, linecolor=black, origin={#1,0}](-11.2,52.8)(11.2,52.8)
\psline[linewidth=0.6, linecolor=black, origin={#1,0}](-11.2,56.1)(11.2,56.1)
}

\newcommand{\tige}[4][1]{%
\setcounter{xx}{20*(#2-1+#1)-10}\setcounter{yy}{\value{xx}-1}%
\support{\value{xx}}
\ifnum#3>4\bille{\value{xx},62}{\colbil}\else\bille{\value{xx},68.2}{\colbil}\fi
\ifcase#3\psforeach{\m}{5.3,16,26.7,37.4}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,16,26.7,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,16,36.3,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,25.6,36.3,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{14.9,25.6,36.3,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,16,26.7,37.4}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,16,26.7,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,16,36.3,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{5.3,25.6,36.3,46.9}{\bille{\value{xx},\m}{\colbil}}
\or\psforeach{\m}{14.9,25.6,36.3,46.9}{\bille{\value{xx},\m}{\colbil}}
\fi
\ifnum#4=1\pscircle*[fillcolor=black](\value{xx},54.4){1}\fi
}

\newcommand{\binoire}[4][1]{%
\setcounter{xx}{20*(#2-1+#1)-10}
\ifcase#3{}
\or\bille{\value{xx},5.3}{#4}       %   1 = 1 en bas  xooo  oo
\or\bille{\value{xx},16}{#4}        %   2 = 2         oxoo  oo
\or\bille{\value{xx},26.7}{#4}      %   3 = 3         ooxo  oo
\or\bille{\value{xx},37.4}{#4}      %   4 = 4         ooox  oo
\or\bille{\value{xx},46.9}{#4}      %   5 = 6         ooo x oo
\or\bille{\value{xx},36.3}{#4}      %   6 = 7         oo xo oo
\or\bille{\value{xx},25.6}{#4}      %   7 = 8         o xoo oo
\or\bille{\value{xx},14.9}{#4}      %   8 = 9          xooo oo
\or\bille{\value{xx},68.2}{#4}      %   9 = 5 * 0     oooo  ox
\or\bille{\value{xx},62}{#4}        %  10 = 5 * 1     oooo  xo
\fi
}

\newcommand{\barbil}[3][1]{%
\setcounter{xx}{20*(#2-1+#1)-10}\psset{linecolor=black,linewidth=1}
\ifcase#3{}
\or\psline[origin={\value{xx},5.3}]{c-c}(-8.6,-5.3)(8.6,5.3)     %   1 = 1 en bas  xooo  oo
\or\psline[origin={\value{xx},16}]{c-c}(-8.6,-5.3)(8.6,5.3)      %   2 = 2         oxoo  oo
\or\psline[origin={\value{xx},26.7}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   3 = 3         ooxo  oo
\or\psline[origin={\value{xx},37.4}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   4 = 4         ooox  oo
\or\psline[origin={\value{xx},46.9}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   5 = 6         ooo x oo
\or\psline[origin={\value{xx},36.3}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   6 = 7         oo xo oo
\or\psline[origin={\value{xx},25.6}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   7 = 8         o xoo oo
\or\psline[origin={\value{xx},14.9}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   8 = 9          xooo oo
\or\psline[origin={\value{xx},68.2}]{c-c}(-8.6,-5.3)(8.6,5.3)    %   9 = 5 * 0     oooo  ox
\or\psline[origin={\value{xx},62}]{c-c}(-8.6,-5.3)(8.6,5.3)      %  10 = 5 * 1     oooo  xo
\fi
}

\newcommand{\cadre}[2][1]{\setcounter{xx}{20*(#2-1+#1) + 1}%
\psframe[linecolor=black, linewidth=2, framearc=.1](-1.2,-1.2)(\value{xx},74.65)
}

\newcommand{\barres}[2][1]{%
\setcounter{xx}{20*(#1)-21}%
\setcounter{yy}{20*(#2-1+#1) + 1}%
\psline[linecolor=black, linewidth=2](\value{xx},-1.2)(\value{yy},-1.2)
\psline[linecolor=black, linewidth=2](\value{xx}, 74.65)(\value{yy}, 74.65)
}
