| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% animated metronome |
| 3 |
% this code is based to 99.9 percent on the work by Manuel Luque |
| 4 |
% (pstricks.blogspot.com) |
| 5 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6 |
\makeatletter |
| 7 |
\pst@addfams{pst-metronome} |
| 8 |
\define@key[psset]{pst-metronome}{theta0}{\def\psk@oscmetronomethetai{#1 }} |
| 9 |
\psset[pst-metronome]{theta0=45} % position initiale du metronome |
| 10 |
\define@key[psset]{pst-metronome}{M}{\def\psk@oscmetronometM{#1 }} |
| 11 |
\psset[pst-metronome]{M=25} % masse du disque en g |
| 12 |
\define@key[psset]{pst-metronome}{m}{\def\psk@oscmetronometm{#1 }} |
| 13 |
\psset[pst-metronome]{m=6} % masse du curseur en g |
| 14 |
\define@key[psset]{pst-metronome}{r}{\def\psk@oscmetronomer{#1 }} |
| 15 |
\psset[pst-metronome]{r=1} % rayon du disque en cm |
| 16 |
\define@key[psset]{pst-metronome}{x}{\def\psk@oscmetronomex{#1 }} |
| 17 |
\psset[pst-metronome]{x=8.4} % position du curseur en cm par rapport à l'axe |
| 18 |
\define@key[psset]{pst-metronome}{d}{\def\psk@oscmetronomed{#1 }} |
| 19 |
\psset[pst-metronome]{d=3.2} % distance de l'axe au centre du disque en cm |
| 20 |
\define@key[psset]{pst-metronome}{dt}{\def\psk@oscmetronomedt{#1 }} |
| 21 |
\psset[pst-metronome]{dt=0.01} % pas pour RK4 |
| 22 |
\define@key[psset]{pst-metronome}{nT}{\def\psk@oscmetronomenT{#1 }} |
| 23 |
\psset[pst-metronome]{nT=1} % nombre de périodes représentées |
| 24 |
%---- calculer theta(t) et thetapoint(t) -------- |
| 25 |
\def\psmetronome{\pst@object{psmetronome}} |
| 26 |
\def\psmetronome@i{% |
| 27 |
\begingroup% |
| 28 |
\use@par% |
| 29 |
\begin@SpecialObj% |
| 30 |
\pstVerb{% |
| 31 |
/deg2rad {180 div 3.14159 mul} def |
| 32 |
/rad2deg {180 mul 3.14159 div} def |
| 33 |
/gp 9.8 def % pesanteur |
| 34 |
/radius \psk@oscmetronomer 1e-2 mul def % en m |
| 35 |
/OA \psk@oscmetronomed 1e-2 mul def % distance de l'axe au centre du disque en m |
| 36 |
/xC \psk@oscmetronomex 1e-2 mul def % position du curseur en m par rapport à l'axe |
| 37 |
/theta0 \psk@oscmetronomethetai def % en degrés |
| 38 |
/theta0rad theta0 deg2rad def % en radians |
| 39 |
/Md \psk@oscmetronometM 1e-3 mul def % en kg |
| 40 |
/mc \psk@oscmetronometm 1e-3 mul def % en kg |
| 41 |
/dt \psk@oscmetronomedt def |
| 42 |
/nT \psk@oscmetronomenT def |
| 43 |
% moment d'inertie du métronome |
| 44 |
% J=1/2M*R^2+M*a^2+m*x^2 |
| 45 |
/Ji {0.5 Md mul radius dup mul mul Md OA dup mul mul add mc xC dup mul mul add} def |
| 46 |
/AT {4 |
| 47 |
Ji |
| 48 |
gp Md OA mul mc xC mul sub mul |
| 49 |
div |
| 50 |
sqrt |
| 51 |
mul} def |
| 52 |
% Pour le calcul de la période |
| 53 |
% coefficients de l'approximation polynômiale du calcul |
| 54 |
% de l'intégrale elliptique |
| 55 |
% coefficient pour le calcul de l'intégrale elliptique |
| 56 |
/m0 theta0 2 div sin def |
| 57 |
/m1 {1 m0 dup mul sub} def |
| 58 |
/m2 {m1 dup mul} def |
| 59 |
/m3 {m2 m1 mul} def |
| 60 |
/m4 {m2 dup mul} def |
| 61 |
/m_1 {1 m1 div} def |
| 62 |
/EllipticK { |
| 63 |
0.5 |
| 64 |
0.12498593597 m1 mul add |
| 65 |
0.06880248576 m2 mul add |
| 66 |
0.03328355376 m3 mul add |
| 67 |
0.00441787012 m4 mul add |
| 68 |
m_1 ln mul |
| 69 |
1.38629436112 add |
| 70 |
0.09666344259 m1 mul add |
| 71 |
0.03590092383 m2 mul add |
| 72 |
0.03742563713 m3 mul add |
| 73 |
0.01451196212 m4 mul add |
| 74 |
} def |
| 75 |
/Tm {AT EllipticK mul} def |
| 76 |
% tableau des valeurs de theta(t) |
| 77 |
/W 0 def % vitesse angulaire |
| 78 |
/theta theta0 def |
| 79 |
/oscillateur {sin gp Md OA mul mc xC mul sub mul neg mul Ji div} def |
| 80 |
/j1 {W dt mul} def |
| 81 |
/k1 {theta oscillateur dt mul} def |
| 82 |
/j2 {W k1 2 div add dt mul} def |
| 83 |
/k2 {theta j1 2 div rad2deg add oscillateur dt mul} def |
| 84 |
/j3 {W k2 2 div add dt mul} def |
| 85 |
/k3 {theta j2 2 div rad2deg add oscillateur dt mul} def |
| 86 |
/j4 {W k3 add dt mul} def |
| 87 |
/k4 {theta j3 rad2deg add oscillateur dt mul} def |
| 88 |
/theta2 {theta j1 rad2deg 2 j2 rad2deg j3 rad2deg add mul add j4 rad2deg add 6 div add} def |
| 89 |
/tabTheta [ % pour l'animation |
| 90 |
0 theta0 % date angle |
| 91 |
dt dt Tm nT mul{ % |
| 92 |
theta2 % |
| 93 |
/W2 W k1 2 k2 k3 add mul add k4 add 6 div add def |
| 94 |
/theta theta2 def |
| 95 |
/W W2 def |
| 96 |
} for |
| 97 |
] def |
| 98 |
/Nvaleurs tabTheta length 2 div cvi def |
| 99 |
/W 0 def % vitesse angulaire |
| 100 |
/theta theta0 def |
| 101 |
/tabThetaGraph [ % pour le graphique theta(t) |
| 102 |
0 theta0 % date angle |
| 103 |
0 dt Tm nT mul { % pop |
| 104 |
theta2 % 180 div 3.14159 mul |
| 105 |
/W2 W k1 2 k2 k3 add mul add k4 add 6 div add def |
| 106 |
/theta theta2 def |
| 107 |
/W W2 def |
| 108 |
} for |
| 109 |
] def |
| 110 |
/W 0 def % vitesse angulaire |
| 111 |
/theta theta0 def |
| 112 |
/tabThetaPoint [ % pour le graphique thetapoint(t) |
| 113 |
0 0 % date angle |
| 114 |
dt dt Tm nT mul { % pop |
| 115 |
% theta2 % 180 div 3.14159 mul |
| 116 |
/W2 W k1 2 k2 k3 add mul add k4 add 6 div add def |
| 117 |
W2 |
| 118 |
/theta theta2 def |
| 119 |
/W W2 def |
| 120 |
} for |
| 121 |
] def |
| 122 |
/tabXOSC [ % oscillations par min en fonction de x |
| 123 |
0.5 0.1 12 {/xc exch def |
| 124 |
/xC xc 1e-2 mul def |
| 125 |
xc 60 Tm div % cvi |
| 126 |
} for |
| 127 |
] def |
| 128 |
/tabXbattements [ % battements par min en fonction de x |
| 129 |
3 0.1 12 {/xc exch def |
| 130 |
/xC xc 1e-2 mul def |
| 131 |
xc 60 Tm div 2 mul % cvi |
| 132 |
} for |
| 133 |
] def |
| 134 |
% graduation T --> x |
| 135 |
/tabXT [ % [T,x] |
| 136 |
40 1 220 {/batt exch def % battements |
| 137 |
/Tmetronome2 120 batt div dup mul def |
| 138 |
/A1 16 mc mul EllipticK dup mul mul def |
| 139 |
/B1 gp Tmetronome2 mul mc mul def |
| 140 |
/C1 gp Md mul OA mul Tmetronome2 mul neg |
| 141 |
8 Md mul radius dup mul mul 16 Md mul OA dup mul mul add EllipticK dup mul mul add def |
| 142 |
/Delta B1 dup mul 4 A1 mul C1 mul sub sqrt def |
| 143 |
/xC1 B1 neg Delta sub 2 div A1 div def |
| 144 |
/xC2 B1 neg Delta add 2 div A1 div def |
| 145 |
xC2 0 ge {/posC xC2 def}{/posC xC1 def} ifelse |
| 146 |
batt posC 1e2 mul |
| 147 |
} for |
| 148 |
] def |
| 149 |
/xT { % pour une valeur particulière battement -> position du curseur |
| 150 |
/batt exch def |
| 151 |
/Tmetronome2 120 batt div dup mul def |
| 152 |
/A1 16 mc mul EllipticK dup mul mul def |
| 153 |
/B1 gp Tmetronome2 mul mc mul def |
| 154 |
/C1 gp Md mul OA mul Tmetronome2 mul neg |
| 155 |
8 Md mul radius dup mul mul 16 Md mul OA dup mul mul add EllipticK dup mul mul add def |
| 156 |
/Delta B1 dup mul 4 A1 mul C1 mul sub sqrt def |
| 157 |
/xC1 B1 neg Delta sub 2 div A1 div def |
| 158 |
/xC2 B1 neg Delta add 2 div A1 div def |
| 159 |
xC2 0 ge {/posC xC2 def}{/posC xC1 def} ifelse |
| 160 |
posC 1e2 mul |
| 161 |
} def |
| 162 |
/xC \psk@oscmetronomex 1e-2 mul def % position du curseur en m par rapport à l'axe |
| 163 |
/Tm {AT EllipticK mul} def |
| 164 |
}% |
| 165 |
\end@SpecialObj% |
| 166 |
\endgroup} |
| 167 |
% |
| 168 |
\def\psmetronomeA{\pst@object{psmetronomeA}} |
| 169 |
\def\psmetronomeA@i{% |
| 170 |
\begingroup% |
| 171 |
\use@par% |
| 172 |
\begin@SpecialObj% |
| 173 |
\pstVerb{% |
| 174 |
/radius \psk@oscmetronomer 1e-2 mul def % en m |
| 175 |
/OA \psk@oscmetronomed 1e-2 mul def % distance de l'axe au centre du disque en m |
| 176 |
/xC \psk@oscmetronomex 1e-2 mul def % position du curseur en m par rapport à l'axe |
| 177 |
}% |
| 178 |
\psframe[fillstyle=solid](! -0.075 \psk@oscmetronomed neg)(0.075,13) |
| 179 |
\pscircle[fillstyle=solid,fillcolor={[rgb]{0.75 0.75 0.75}}](! 0 \psk@oscmetronomed neg){!radius 1e2 mul} |
| 180 |
\pscircle[fillstyle=solid,linewidth=0.05](0,0){0.15} |
| 181 |
\pscircle*[linecolor=red](0,0){0.05} |
| 182 |
% curseur |
| 183 |
\pspolygon[fillstyle=solid](! -0.25 \psk@oscmetronomex 0.5 sub)(! -0.5 \psk@oscmetronomex 0.5 add)(!-0.075 \psk@oscmetronomex 0.5 add)(!-0.075 \psk@oscmetronomex 0.5 sub) |
| 184 |
\pspolygon[fillstyle=solid](! 0.25 \psk@oscmetronomex 0.5 sub)(! 0.5 \psk@oscmetronomex 0.5 add)(!0.075 \psk@oscmetronomex 0.5 add)(!0.075 \psk@oscmetronomex 0.5 sub) |
| 185 |
\pspolygon[fillstyle=solid,fillcolor=gray](! -0.25 \psk@oscmetronomex 0.5 sub)(! -0.3 \psk@oscmetronomex 0.3 sub)(! -0.075 \psk@oscmetronomex 0.3 sub)(!-0.075 \psk@oscmetronomex 0.3 add)(!0.075 \psk@oscmetronomex 0.3 add)(!0.075 \psk@oscmetronomex 0.3 sub)(!0.3 \psk@oscmetronomex 0.3 sub)(!0.25 \psk@oscmetronomex 0.5 sub) |
| 186 |
\pscircle[fillstyle=solid](!-0.125 \psk@oscmetronomex 0.4 sub){0.08} |
| 187 |
\pscircle[fillstyle=solid](!0.125 \psk@oscmetronomex 0.4 sub){0.08} |
| 188 |
% fin curseur |
| 189 |
{\psset{linecolor=red} |
| 190 |
\psline(!-.1 \psk@oscmetronomex)(!0.1 \psk@oscmetronomex)\psline(!0 \psk@oscmetronomex 0.1 sub)(!0 \psk@oscmetronomex 0.1 add) |
| 191 |
\psline(! -.1 \psk@oscmetronomed neg)(!0.1 \psk@oscmetronomed neg)\psline(! 0 \psk@oscmetronomed neg 0.1 sub)(!0 \psk@oscmetronomed neg 0.1 add)} |
| 192 |
\pnode(!0 \psk@oscmetronomex){C}% curseur |
| 193 |
\pnode(! 0 \psk@oscmetronomed neg){D}% disque |
| 194 |
%\pstextpath[c](0,-2ex){\psarcn[linestyle=none](D){1}{180}{0}}{\small\textsf{\textbf{m e t r o n o m e}}} |
| 195 |
%\pstextpath[c](0,1ex){\psarc[linestyle=none](D){1}{180}{0}}{\small\textsf{\textbf{P S t r i c k s}}} |
| 196 |
\end@SpecialObj% |
| 197 |
\endgroup} |
| 198 |
\psmetronome% |
| 199 |
\pstVerb{/tabTempos [40 42 44 46 48 50 52 54 46 58 60 63 66 69 72 76 80 84 88 92 96 100 104 108 112 116 120 126 132 138 144 152 160 168 176 184 192 200 208] def}% |
| 200 |
|
| 201 |
\def\metronomebody{% |
| 202 |
\pspolygon[fillstyle=solid,linewidth=2\pslinewidth,linearc=0.5,fillcolor=yellow!30](-5,-4.5)(5,-4.5)(1,14)(-1,14) |
| 203 |
\psline(1.2,4.5)(1.2,12.5) |
| 204 |
\psline(-1.2,4.5)(-1.2,12.5) |
| 205 |
\multido{\i=0+2}{20}{% |
| 206 |
\pstVerb{/BATT tabTempos \i\space get def} |
| 207 |
\psline[linecolor=red](!1.2 BATT xT)(!0.7 BATT xT) |
| 208 |
\uput[r](!0.7 BATT xT){\psPrintValue[PSfont=Helvetica,fontscale=6]{BATT}} |
| 209 |
}% |
| 210 |
\multido{\i=1+2}{19}{% |
| 211 |
\pstVerb{/BATT tabTempos \i\space get def} |
| 212 |
\psline[linecolor=red](!-1.2 BATT xT)(!-0.7 BATT xT) |
| 213 |
\uput[r](!-1.3 BATT xT){\psPrintValue[PSfont=Helvetica,fontscale=6]{BATT}}}% |
| 214 |
\rput(!0 40 xT){\textsf{\tiny GRAVE}}% |
| 215 |
\rput(!0 46 xT){\textsf{\tiny LARGO}}% |
| 216 |
\rput(!0 52 xT){\textsf{\tiny LENTO}}% |
| 217 |
\rput(!0 58 xT){\textsf{\tiny ADAGIO}}% |
| 218 |
\rput(!0 60 xT){\textsf{\tiny LARGETTO}}% |
| 219 |
\rput(!0 66 xT){\textsf{\tiny ANDANTE}}% |
| 220 |
\rput(!0 76 xT){\textsf{\tiny ANDANTINO}}% |
| 221 |
\rput(!0 84 xT){\textsf{\tiny MODERATO}}% |
| 222 |
\rput(!0 108 xT){\textsf{\tiny ALLEGRETTO}}% |
| 223 |
\rput(!0 132 xT){\textsf{\tiny ALLEGRO}}% |
| 224 |
\rput(!0 160 xT){\textsf{\tiny VIVACE}}% |
| 225 |
\rput(!0 184 xT){\textsf{\tiny PRESTO}}% |
| 226 |
\rput(!0 200 xT){\textsf{\tiny PRESTISSIMO}}% |
| 227 |
} |
| 228 |
|
| 229 |
\def\pendulum#1{% |
| 230 |
\pstVerb{/iA #1\space def /date tabTheta iA get def /Theta tabTheta iA 1 add get def}% |
| 231 |
\rput{!Theta}{\psmetronomeA}% |
| 232 |
} |
| 233 |
\makeatother |