%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%%
%% Author:   Manuel Luque <manuel.luque27@gmail.com>
%%           Herbert Voß <hvoss@tug.org>   
%%
\csname PSTHYPTILLoaded\endcsname
\let\PSTHYPTILLoaded\endinput
% Requires some packages
\ifx\PSTricksLoaded\endinput\else \input pstricks \fi
\ifx\PSTXKeyLoaded\endinput\else  \input pst-xkey \fi
\def\fileversion{0.01}
\def\filedate{2026/05/30}
\message{`PSTHYPTILLoaded' v\fileversion, \filedate}

\pstheader{pst-hypertiling.pro}

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\pst@addfams{pst-hyptil}
\define@key[psset]{pst-hyptil}{polygonbasecolor}[red]{\pst@getcolor{#1}\polygonbasecolor}
\psset[pst-hyptil]{polygonbasecolor=red}
\define@key[psset]{pst-hyptil}{polygoncolor}[red]{\pst@getcolor{#1}\polygoncolor}
\psset[pst-hyptil]{polygoncolor=red}
\define@key[psset]{pst-hyptil}{colorA}[red]{\pst@getcolor{#1}\colorA}
\psset[pst-hyptil]{colorA={[rgb]{0.75 0 0.25}}}
\define@key[psset]{pst-hyptil}{colorB}[white]{\pst@getcolor{#1}\colorB}
\psset[pst-hyptil]{colorB={[rgb]{0.25 1 0.75}}}
\newdimen\polygonbasewidth
\define@key[psset]{pst-hyptil}{polygonbasewidth}[1.5pt]{\pssetlength\polygonbasewidth{#1}}
\psset[pst-hyptil]{polygonbasewidth=1.5pt}
\newdimen\polygonwidth
\define@key[psset]{pst-hyptil}{polygonwidth}[0.8pt]{\pssetlength\polygonwidth{#1}}
\psset[pst-hyptil]{polygonwidth=0.8pt}
\define@key[psset]{pst-hyptil}{np}{\def\psk@np{#1 }}
\psset[pst-hyptil]{np=6 4}
\define@key[psset]{pst-hyptil}{ni}{\def\psk@ni{#1}}
\psset[pst-hyptil]{ni=2}
\define@key[psset]{pst-hyptil}{subdiv}{\def\psk@subdiv{#1 }}
\psset[pst-hyptil]{subdiv=5}
%%
% nature de la transformation
%% Reservation des noms de macros
% adaptation de la macro de pst-solides3d
% #1=type de reservation associee a une liste qui
% doit forcement etre du type pst@anamorphosis@list@#1
\def\pst@hyptil@reservednames#1{%
\edef\@tempa{\csname pst@hyptil@list@#1\endcsname}
\@for \name:=\@tempa\do{%
  \expandafter\def\csname pst@hyptil@#1@\name\endcsname{}%
}}

\def\pst@hyptil@list@type{SymMiddle,Reflect}
%
%% Reservation de macros correspondants aux types
\pst@hyptil@reservednames{type}
\define@key[psset]{pst-hyptil}{type}{%
 \ifcsname pst@hyptil@type@#1\endcsname
   \def\psk@hyptil@type{#1}%
 \else
    \@pstrickserr{The hyptil #1 is not defined, the "The symmetry in the middle of the side of the polygon" by default is
    drawn}{}%
 \fi}
\psset[pst-hyptil]{type=SymMiddle}
%% === pour dessiner motifs, polygones, et polygone de base
\newif\ifPst@motifA
\define@key[psset]{pst-hyptil}{motifA}[true]{\@nameuse{Pst@motifA#1}}
\psset[pst-hyptil]{motifA=true}
\newif\ifPst@motifB
\define@key[psset]{pst-hyptil}{motifB}[true]{\@nameuse{Pst@motifB#1}}
\psset[pst-hyptil]{motifB=true}
\newif\ifPst@polygones
\define@key[psset]{pst-hyptil}{polygones}[true]{\@nameuse{Pst@polygones#1}}
\psset[pst-hyptil]{polygones=true}
\newif\ifPst@polygonebase
\define@key[psset]{pst-hyptil}{polygonebase}[true]{\@nameuse{Pst@polygonebase#1}}
\psset[pst-hyptil]{polygonebase=true}
%%
\pst@def{optionshyptil}<%
%%-- type de polygone de base --- (n,p)
  /n_ {[\psk@np] 0 get} bind def
  /p_ {[\psk@np] 1 get} bind def
%% --- niveau de recursion ---
  /ni {\psk@ni} def
%%-- caracteristiques geometriques du polygone --
  /angle_np 180 dup p_ div exch n_ div add def
  /u_ angle_np sin angle_np cos 180 n_ div tan div add def
  /r_ 1 u_ dup mul 1 sub sqrt div def
  /r0 1 r_ dup mul add sqrt r_ sub def
  /r1 1 r_ dup mul add sqrt def
  /anglePolygone 360 n_ div def
  /alpha 180 0.5 1 p_ div sub 1 n_ div sub mul def
  /polygonbasecolor  {\pst@usecolor\polygonbasecolor currentrgbcolor} def
  /polygoncolor  {\pst@usecolor\polygoncolor currentrgbcolor} def
  /colorA  {\pst@usecolor\colorA currentrgbcolor} def
  /colorB  {\pst@usecolor\colorB currentrgbcolor} def
  /polygonbasewidth {\pst@number\polygonbasewidth SLW} def
  /polygonwidth {\pst@number\polygonwidth SLW} def
  /Type {\psk@hyptil@type} def
%%-- precision du trac� ---
 /dl \psk@subdiv def
 /dl_ 1 dl div def
>

\def\psHypertiling{\def\pst@par{}\pst@object{pshyptil}}
\def\pshyptil@i{%
  \begin@ClosedObj
  \addto@pscode{
  	\tx@optionshyptil
  	1 setlinejoin
	/cm {\pst@number\psunit mul } bind def
	% calculs et dessins des motifs triangulaires
	\ifPst@motifA
	  gsave
      ni {colorA} MotifTriangleA DrawMotifs
	  grestore
	\fi
	\ifPst@motifB
 	  gsave
      ni {colorB} MotifTriangleB DrawMotifs
	  grestore
	\fi
	\ifPst@polygones
	  gsave
      polygoncolor
      polygonwidth
      ni n_ POLYGON DRAWPOLYGONES
	  grestore
	\fi
	\ifPst@polygonebase
      POLYGON DrawPolygonBase
	\fi
  }%
  \end@ClosedObj
}%
%
 \catcode`\@=\PstAtCode\relax
\endinput 