Une horloge PSTricks affichant les heures, les minutes et les secondes, dont les caractéristiques du train d'engrenages ont été recopiées sur celui dessiné sur le site :
http://tavmjong.free.fr/INKSCAPE/
L'horaire affiché est celui de la compilation, fichiers : (horloge3.tex et horloge3.pdf) dans :
Le code :
\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{pstricks,pst-node,multido}
\usepackage{datetime}
\SpecialCoor
% version n°6
\makeatletter
\pst@addfams{pst-gears}
\define@key[psset]{pst-gears}{Z1}{\def\psk@ZA{#1 }}
\psset[pst-gears]{Z1=20}
\define@key[psset]{pst-gears}{Z2}{\def\psk@ZB{#1 }}
\psset[pst-gears]{Z2=10}
\define@key[psset]{pst-gears}{m}{\def\psk@m{#1 }}
\psset[pst-gears]{m=0.5}
\define@key[psset]{pst-gears}{ap}{\def\psk@ap{#1 }}
\psset[pst-gears]{ap=20}
\define@key[psset]{pst-gears}{wheelrotation}{\def\psk@wheelrotation{#1 }}
\psset[pst-gears]{wheelrotation=0}
\define@key[psset]{pst-gears}{color1}{\pst@getcolor{#1}\pscolora}
\psset[pst-gears]{color1={[rgb]{0.625 0.75 1}}}
\define@key[psset]{pst-gears}{color2}{\pst@getcolor{#1}\pscolorb}
\psset[pst-gears]{color2={[rgb]{0.75 1 0.75}}}
\define@key[psset]{pst-gears}{colorcircles}{\pst@getcolor{#1}\pscolorc}
\psset[pst-gears]{colorcircles=red}
%
%% === Option pour ne pas dessiner le type d'engrenage ---------------------
\newif\ifPst@gears@int
\define@key[psset]{pst-gears}{int}[true]{\@nameuse{Pst@gears@int#1}}
\psset[pst-gears]{int=false}
%
%% === pour dessiner cercle de base et cercle primitif
\newif\ifPst@gears@circles
\define@key[psset]{pst-gears}{circles}[true]{\@nameuse{Pst@gears@circles#1}}
\psset[pst-gears]{circles=false}
%
\def\pstgears{\def\pst@par{}\pst@object{pstgears}}
\def\pstgears@i{\@ifnextchar({\pstgears@do}{\pstgears@do(0,0)}}
\def\pstgears@do(#1){%
\begin@SpecialObj
\pst@@getcoor{#1}%
\addto@pscode{%
\pst@coor /t@@y ED /t@@x ED
/cm {\pst@number\psunit mul } bind def
/Z1 \psk@ZA def
/m1 \psk@m def
/Z2 \psk@ZB def
/m2 \psk@m def
/ap \psk@ap def
/color1 {\pst@usecolor\pscolora } def
/color2 {\pst@usecolor\pscolorb } def
/colorcircles {\pst@usecolor\pscolorc } def
/linecolor {\pst@usecolor\pslinecolor} def
/Pi 3.14159265359 def
/rad2deg { 180 mul Pi div } bind def
/deg2rad { 180 div Pi mul } bind def
/Datas1 {
/Z@ exch def
/m@ exch def
/R@ {m@ Z@ mul 2 div } bind def % cercle primitif
/Rb {R@ 20 cos mul } bind def % cercle de base
/Rp {R@ 2 mul 2.5 m@ mul sub 2 div } bind def % cercle de pied
/Rt {R@ 2 mul 2 m@ mul add 2 div } bind def % cercle de tête
} def
/Datas2 {
/Z@ exch def
/m@ exch def
/R@ {m@ Z@ mul 2 div } bind def % cercle primitif
/Rb {R@ 20 cos mul } bind def % cercle de base
/Rp {R@ 2 mul 2 m@ mul sub 2 div } bind def % cercle de pied
/Rt {R@ 2 mul 2.5 m@ mul add 2 div } bind def % cercle de tête
} def
/Calculs {
R@ 1 ge {
/rScrew R@ 10 div cm def
}{
/rScrew R@ 5 div cm def
} ifelse
% les valeurs suivantes sont en radians
/ThetaP {R@ Rb div dup mul 1 sub sqrt } bind def % intersection avec cercle primitif
/ThetaT {Rt Rb div dup mul 1 sub sqrt } bind def % intersection avec cercle de tete
% Les valeurs suivantes ont en degrés
/ThetaTdeg {Rt Rb div dup mul 1 sub sqrt rad2deg } bind def %
/ThetaPdeg {R@ Rb div dup mul 1 sub sqrt rad2deg } bind def
/DeltaP {ThetaPdeg sin ThetaP ThetaPdeg cos mul sub
ThetaPdeg cos ThetaP ThetaPdeg sin mul add
atan } bind def
/DeltaT {ThetaTdeg sin ThetaT ThetaTdeg cos mul sub
ThetaTdeg cos ThetaT ThetaTdeg sin mul add
atan } bind def
/DeltaS {Pi 2 div Z@ div } bind def
/DeltaSdeg {90 Z@ div } bind def
/AngleDent {360 Z@ div} bind def
/Alpha {DeltaSdeg DeltaP add DeltaT sub } bind def
/2Beta {DeltaSdeg DeltaP add 2 mul } bind def
/Beta_ {DeltaSdeg DeltaP add neg} bind def
Rp Rb gt {/Rp Rb def} if
/ptA {Rp cm 0} bind def
/ptB {Rb cm 0} bind def
/ptC {Rp cm DeltaSdeg 2 mul neg 2Beta 2 div add cos mul
Rp cm DeltaSdeg 2 mul neg 2Beta 2 div add sin mul} bind def
/ptA'{Rp cm DeltaP DeltaSdeg add 2 mul cos mul
Rp cm DeltaP DeltaSdeg add 2 mul sin mul} bind def
/ptB'{Rb cm DeltaP DeltaSdeg add 2 mul cos mul
Rb cm DeltaP DeltaSdeg add 2 mul sin mul} bind def
/ptC'{Rp cm DeltaSdeg 3 mul DeltaP add cos mul
Rp cm DeltaSdeg 3 mul DeltaP add sin mul} bind def
/Raxe {Rp 4 div } bind def
/A@0 14.5 def % position et largeur de la clavette
% rayon de raccordement sur le cercle de pied
/Rarct {Rp Pi mul Z@ div 12 div cm} bind def
}
def
% Le symetrique P' de P par rapport a la l'axe de la dent
% Delta(axe de la dent) y=x*tan(Beta)
% x'=y*sin(2*Beta)+x*cos(2*Beta)
% y'=x*sin(2*Beta)-y*cos(2*Beta)
% x y symAxe -> x' y'
/symAxe {
2 dict begin
/y exch def
/x exch def
y 2Beta sin mul x 2Beta cos mul add % x'
x 2Beta sin mul y 2Beta cos mul sub % y'
end
}
def
%
% Rotation pour amener l'axe de la dent horizontal
%
/RotDent {
2 dict begin
/y exch def
/x exch def
i@ cos x mul i@ sin y mul sub
i@ sin x mul i@ cos y mul add
end
} def
%
% developpante du cercle de base
%
/devCercle {
1 dict begin
/t exch def % en degres
Rb t cos t deg2rad t sin mul add mul cm % x
Rb t sin t deg2rad t cos mul sub mul cm % y
end
}
def
% trace des cercles
/Circles {
gsave
[ \psk@dash\space ] 0 setdash
newpath
0 0 R@ cm 0 360 arc
closepath
colorcircles
stroke
newpath
0 0 Rb cm 0 360 arc
closepath
stroke
grestore
} def
%%%% definition de la roue dentee %%%%%%
/Roue {
% arc de développante
/tabArcDev [
0 1 ThetaTdeg { /i@ exch def
[i@ devCercle] } for
] def
%
/n@ tabArcDev length def
%
/tabDent [
% l'arc de developpante initial
tabArcDev aload pop
% l'arc ce cercle de tete
DeltaT 0.1 2Beta DeltaT sub {/i@ exch def
[Rt cm i@ cos mul
Rt cm i@ sin mul]
} for
% le symetrique de l'arc de developpante par rapport a l'axe de la dent
n@ 1 sub -1 0 {
/compteur exch def
[tabArcDev compteur get aload pop symAxe]
} for
] def
% tracé de la dent
/n2@ tabDent length def
newpath
ptC moveto
0 1 Z@ 1 sub {/i@ exch AngleDent mul def
\ifPst@gears@int
wheel 2 eq {
ptA RotDent ptB RotDent Rarct arct
ptB RotDent lineto
}{
ptA RotDent lineto ptB RotDent lineto}
ifelse
\else
Rp Rb eq {
ptA RotDent lineto ptB RotDent lineto
}{
ptA RotDent ptB RotDent Rarct arct
ptB RotDent lineto }
ifelse
\fi
0 1 n2@ 1 sub {
/compteur exch def
tabDent compteur get aload pop
RotDent lineto } for
\ifPst@gears@int
wheel 2 eq {
Rp Rb eq {
ptA' RotDent lineto ptC' RotDent lineto
}{
ptA' RotDent ptC' RotDent Rarct arct
ptC' RotDent lineto }
ifelse
} {
ptA' RotDent lineto ptC' RotDent lineto }
ifelse
\else
Rp Rb eq {
ptA' RotDent lineto ptC' RotDent lineto
}{
ptA' RotDent ptC' RotDent Rarct arct
ptC' RotDent lineto }
ifelse
\fi
} for
} def
%%%% fin de la definition de la roue dentee %%%
%%% axe de la roue %%%
%/AXE {
% Raxe 4 div cm
% A@0 cos Raxe mul cm moveto
% 0 0 Raxe cm 90 A@0 sub 90 A@0 add arcn
% Raxe 4 div cm neg
% A@0 cos Raxe mul cm
% lineto
% Raxe 4 div cm neg
% Raxe A@0 cos 0.2 add mul cm
% lineto
% Raxe 4 div cm
% Raxe A@0 cos 0.2 add mul cm
% lineto
%} def
%%% clavette %%%
%/CLAVETTE {
%newpath
% Raxe 4 div cm
% A@0 cos 0.2 sub Raxe mul cm moveto
% Raxe 4 div cm
% Raxe A@0 cos 0.2 add mul cm lineto
% Raxe 4 div cm neg
% Raxe A@0 cos 0.2 add mul cm lineto
% Raxe 4 div cm neg
% A@0 cos 0.2 sub Raxe mul cm lineto
%closepath
%} def
/COURONNE {
% pour l'engrenage interieur
0 0 Rt 1.1 mul cm 360 0 arcn
} def
%=== Style engrenage pour horlogerie ===
/RayonA {
/Alpha 0.1 arcsin def
/Beta 90 Alpha sub def
/A1 {Rayon Alpha cos mul % x
Rayon Alpha sin mul % y
} def
/A2 {Rayon Alpha sin mul % x
Rayon Alpha cos mul % y
} def
/A3 {Rayon 10 div
Rayon 5 div
} def
/A4 {Rayon 5 div
Rayon 10 div
} def
A1 moveto
A4 lineto
Rayon 5 div dup Rayon 10 div 270 180 arcn
A2 lineto
0 0 Rayon Beta Alpha arcn
} def
%
/RayonB {
90 rotate RayonA
} def
/RayonC {
180 rotate RayonA
} def
/RayonD {
270 rotate RayonA
} def
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/AngleRotation \psk@wheelrotation def
gsave
%%% Les dessins de l'engrenage %%%%%%
%%%%%%%%%% Roue N°1 %%%%%%%%%%%%%%%%%
/wheel 1 def
gsave
t@@x t@@y translate
m1 Z1
\ifPst@gears@int
Datas2
Calculs
Beta_ AngleRotation sub rotate
Roue
COURONNE
closepath
\ifx\psk@fillstyle\relax\else
color1
fill
\fi
Roue
closepath
linecolor
stroke
COURONNE
closepath
linecolor
stroke
\ifPst@gears@circles
Circles
\fi
\else
Datas1
Calculs
/Rayon Rp cm 0.8 mul def
Beta_ AngleRotation sub rotate
Roue
gsave
Roue
R@ 1 ge {
RayonA
RayonB
RayonC
RayonD
} if
closepath
\ifx\psk@fillstyle\relax\else
color1
fill
\fi
grestore
Roue
R@ 1 ge {
RayonA
RayonB
RayonC
RayonD
} if
closepath
linecolor
stroke
newpath
0 0 rScrew 0 360 arc
closepath
\ifx\psk@fillstyle\relax\else
color1
fill
\fi
newpath
0 0 rScrew 0 360 arc
closepath
linecolor
stroke
% la vis
rScrew 40 cos mul rScrew 40 sin mul moveto
rScrew 50 cos mul neg rScrew 50 sin mul neg lineto
stroke
rScrew 50 cos mul rScrew 50 sin mul moveto
rScrew 40 cos mul neg rScrew 40 sin mul neg lineto
stroke
\ifPst@gears@circles
Circles
\fi
\fi
grestore
%%%%%%%%%% Roue N°2 %%%%%%%%%%%%%%%%%
/wheel 2 def
gsave
m2 Z2 Datas1
Calculs
/Rayon Rp cm 0.8 mul def
\ifPst@gears@int
m2 Z1 Z2 sub mul 2 div cm t@@x add t@@y translate
Beta_ Z1 Z2 div AngleRotation mul sub rotate
\else
m2 Z1 Z2 add mul 2 div cm t@@x add t@@y translate
DeltaSdeg DeltaP add neg 180 Z2 div add 180 sub Z1 Z2 div AngleRotation mul add rotate
\fi
gsave
Roue
R@ 1 ge {
RayonA
RayonB
RayonC
RayonD
} if
closepath
\ifx\psk@fillstyle\relax\else
color2
fill
\fi
grestore
Roue
R@ 1 ge {
RayonA
RayonB
RayonC
RayonD
} if
closepath
linecolor
stroke
newpath
0 0 rScrew 0 360 arc
closepath
\ifx\psk@fillstyle\relax\else
color2
fill
\fi
newpath
0 0 rScrew 0 360 arc
closepath
linecolor
stroke
% la vis
rScrew 40 cos mul rScrew 40 sin mul moveto
rScrew 50 cos mul neg rScrew 50 sin mul neg lineto
stroke
rScrew 50 cos mul rScrew 50 sin mul moveto
rScrew 40 cos mul neg rScrew 40 sin mul neg lineto
stroke
\ifPst@gears@circles
Circles
\fi
grestore
grestore
}%
\end@SpecialObj}% % fin de la commande PSTricks
%
%\define@key[psset]{pst-gears}{Day}{\edef\psk@gearsJ{#1}}
%\define@key[psset]{pst-gears}{Month}{\edef\psk@gearsM{#1}}
%\define@key[psset]{pst-gears}{Year}{\edef\psk@gearsA{#1}}
\define@key[psset]{pst-gears}{Hour}{\edef\psk@gearsH{#1}}
\define@key[psset]{pst-gears}{Minute}{\edef\psk@gearsMi{#1}}
\define@key[psset]{pst-gears}{Second}{\edef\psk@gearsS{#1}}
%
%\psset{Day=\number\day,Month=\number\month,Year=\number\year}%
\psset{Hour=12,Minute=0,Second=0}
\makeatother
\title{Engrenages}
\date{27 mai 2013}
\begin{document}
\the\currenthour:\the\currentminute:\the\currentsecond
%\the\time
\begin{center}
\begin{pspicture}(-15,-5)(2,3)
\psset{m=0.08,linewidth=0.025,fillstyle=solid}
\psframe*[linecolor=gray!20](-15,-5)(2,3)
\pstVerb{%
/min \the\currentminute\space 6 mul 90 sub neg def
/hour \the\currenthour\space 30 mul min 2 div add 90 sub neg def
/second \the\currentsecond\space 6 mul 90 sub neg def} %
\rput{180}{\pstgears[Z2=60,Z1=8,wheelrotation=0,color2=gray!50,color1={[rgb]{1 0.5 0}}]}
% entraxe1 = (8+60)*0.08/2 = 2.72
\pnode(!/a1 8 60 add 2 div 0.08 mul def
a1 neg 0){O1}
\rput{180}(O1){\pstgears[Z1=8,Z2=64,wheelrotation=second,color1=gray!50]}
% entraxe2 = (8+64)*0.08/2 = 2.88
% position de la roue -(a1+a2)
\pnode(!/a2 8 64 add 2 div 0.08 mul def
a2 neg a1 sub 0){O2}
\rput{210}(O2){\pstgears[Z1=20,Z2=60,wheelrotation=min,color2=gray!50,color1={[rgb]{0.75 1 0.75}}]}
% entraxe3 = (20+60)*0.08/2 = 3.2 + entraxe2 + entraxe1
\pnode(!/a3 20 60 add 2 div 0.08 mul def
/angle2 30 def
/xO3 a3 angle2 cos mul a2 add a1 add neg def
/yO3 a3 angle2 sin mul neg def
xO3 yO3){O3}
\pnode(!/a4 16 64 add 2 div 0.08 mul def
/hx a3 angle2 sin mul def
/angle3 a3 a4 div 30 sin mul dup dup mul neg 1 add sqrt atan def
/angle4 180 angle3 angle2 add sub angle2 add def
/xO4 a1 a2 add neg a3 angle2 cos mul sub a4 angle3 cos mul sub def
xO4 0 ){O4}
\rput{!angle4}(O3){\pstgears[Z1=16,Z2=64,wheelrotation=hour,color1=gray!50,color2=blue!50]}
\psgrid[subgriddiv=0,gridcolor=lightgray,griddots=10,gridlabels=8pt]%
\multido{\i=0+30}{12}{\pscircle(1;\i){0.075}\psdot[linecolor={[rgb]{1 0.5 0}}](1;\i)}
\multido{\i=0+30}{12}{\rput(O2){\pscircle(1.5;\i){0.075}\psdot[linecolor={[rgb]{0.75 1 0.75}}](1.5;\i)}}
\multido{\i=0+30}{12}{\rput(O4){\pscircle(1;\i){0.075}\psdot[linecolor=blue!50](1;\i)}}
\rput{!\the\currentsecond\space -6 mul}{\pstriangle*[linecolor=red](0,-0.2)(0.1,1.5)\psdot(0,0)}
\rput{!\the\currentminute\space -6 mul}(O2){\pstriangle*[linecolor={[rgb]{1 0.9 0.16}}](0,-0.2)(0.2,2)\psdot(0,0)}
\rput{!\the\currenthour\space \the\currentminute\space 60 div add 30 mul neg}(O4){\pstriangle*[linecolor=magenta](0,-0.2)(0.15,1.5)\psdot(0,0)}
\end{pspicture}
\end{center}
\end{document}