Une transformation d'une figure géométrique (sinus autour d'un cercle) dans serie02...
[pst-anamorphosis.git] / img / serie02 / anamorphosis.pro
1 %!
2 % 12 octobre 2011
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %% === Capture de commandes de systemdict --------------------------------------
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 /LINETO    { systemdict /lineto get exec    } def
7 /MOVETO    { systemdict /moveto get exec    } def
8 /CURVETO   { systemdict /curveto get exec   } def
9 /CLOSEPATH { systemdict /closepath get exec } def
10 /RLINETO   { systemdict /rlineto get exec   } def
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 %% === Transformation des commandes de construction des path(s) ----------------
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %% 12/10/2011 : version incomplète et un peu brute !
15 /tx@anamorphosisPathDict 50 dict def tx@anamorphosisPathDict begin
16 /moveto {
17   /s@y ED /s@x ED /c@x s@x def /c@y s@y def
18   s@x s@y Anamorphose MOVETO
19 } bind def
20 /lineto {
21   /c@yt ED /c@xt ED /dx c@xt c@x sub 50 div def /dy c@yt c@y sub 50 div def
22   1 1 50 {dup dx mul c@x add exch dy mul c@y add Anamorphose LINETO} for
23   /c@x c@xt def /c@y c@yt def
24 } bind def
25 /closepath {
26   s@x s@y lineto CLOSEPATH
27 } bind def
28 /curveto {
29   /c@yt ED /c@xt ED
30   /c@yb ED /c@xb ED
31   /c@ya ED /c@xa ED
32   1 1 20 {
33     20 div /s ED 1 s sub /t ED
34     t c@x mul 3 s c@xa mul mul add t mul 3 s s c@xb mul mul mul add t mul s 3 exp c@xt mul add
35     t c@y mul 3 s c@ya mul mul add t mul 3 s s c@yb mul mul mul add t mul s 3 exp c@yt mul add
36     Anamorphose LINETO
37   } for
38   /c@x c@xt def /c@y c@yt def
39 } bind def
40 /curvetoinv {
41   /c@ya ED /c@xa ED
42   /c@yb ED /c@xb ED
43   /c@yt ED /c@xt ED
44   1 1 20 {
45     20 div /s ED 1 s sub /t ED
46     t c@x mul 3 s c@xa mul mul add t mul 3 s s c@xb mul mul mul add t mul s 3 exp c@xt mul add
47     t c@y mul 3 s c@ya mul mul add t mul 3 s s c@yb mul mul mul add t mul s 3 exp c@yt mul add
48     Anamorphose LINETO
49   } for
50   /c@x c@xt def /c@y c@yt def
51 } bind def
52 /rlineto {
53   c@y add exch c@x add exch lineto
54 } bind def
55 end
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %% === L'anamorphose cylindrique -----------------------------------------------
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 /pst-cylindrical {
60   /Yp exch s@@y mul t@@y add def /Xp exch s@@x mul t@@x add def
61   /a Xv Xp sub dup mul Yv Yp sub dup mul add def
62   /b Xv Xp mul Yv Yp mul add Xv dup mul sub Yv dup mul sub def
63   /c R neg Xv dup mul add Yv dup mul add def
64   /d b dup mul a c mul sub 0.5 exp def
65   /rho b neg d sub a div def
66   /alpha 2 1 rho div sub def
67   /xi Xv dup Xp sub rho mul sub def
68   /yi Yv dup Yp sub rho mul sub def
69   /k 2 Xv xi mul Yv yi mul add mul R div def
70   /xv k xi mul Xv sub def
71   /yv k yi mul Yv sub def
72   xv dup xi sub alpha mul sub
73   yv dup yi sub alpha mul sub
74 } def
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %% === L'anamorphose conique ---------------------------------------------------
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 /pst-conical {
79   /Yp exch s@@y mul t@@y add def /Xp exch s@@x mul t@@x add def
80   /rP Xp dup mul Yp dup mul add 0.5 exp def
81   /k Rmirror Zs Zv sub mul Zs rP mul Zv Rmirror mul sub div def
82   /Xi k Xp mul def
83   /Yi k Yp mul def
84   k 0 eq {/Zi Zs def}{/Zi Zv 1 k sub mul def} ifelse
85   /BETA rP Zv Atan def
86   /THETA Rmirror Zs Atan def
87   /ALPHA 90 2 THETA mul sub BETA add def
88   /rI Xi dup mul Yi dup mul add 0.5 exp def
89   /KP' Zi ALPHA sin ALPHA cos div div def
90   /rP' rI KP' add def
91   rP' Xp rP div mul
92   rP' Yp rP div mul
93 } def
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %% === L'anamorphose spherique ---------------------------------------------------
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 /pst-spherical {%
98     /Yp exch s@@y mul t@@y add def /Xp exch s@@x mul t@@x add def
99     /rV Xv dup mul Yv dup mul add Zv dup mul add def
100     /rP Xp dup mul Yp dup mul add def
101     /A rP rV add Xv Xp mul Yv Yp mul add 2 mul sub def
102     /B rP neg Xv Xp mul add Yv Yp mul add def
103     /C rP R sub def
104     /Discriminant B dup mul A C mul sub 0.5 exp def
105     /solution1 B neg Discriminant add
106             A div def
107     /solution2 B neg Discriminant sub
108             A div def
109     solution1 0 gt {/Coeff1 solution1 def}{/Coeff1 solution2 def}
110     ifelse
111     /Xi Xp 1 Coeff1 sub mul Coeff1 Xv mul add def
112     /Yi Yp 1 Coeff1 sub mul Coeff1 Yv mul add def
113     /Zi Coeff1 Zv mul def
114     /Coeff2 2 Xv Xi mul Yv Yi mul add Zv Zi mul add mul R div def % k+2
115     /Xv2 Coeff2 Xi mul Xv sub def
116     /Yv2 Coeff2 Yi mul Yv sub def
117     /Zv2 Coeff2 Zi mul Zv sub def
118     /Coeff3 Zi Zi Zv2 sub div def
119     /Ximage Xi Coeff3 Xv2 Xi sub mul add def
120     /Yimage Yi Coeff3 Yv2 Yi sub mul add def
121     Ximage Yimage}
122     def
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 %% === La perspective ---------------------------------------------------
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 /pst-perspective{
127   /Yp exch s@@y mul t@@y add def /Xp exch s@@x mul t@@x add def
128        Xp xD mul
129        Yp ua add xD add div % x'
130        ua yH xD add mul Yp yH mul add
131       Yp ua add xD add div  % y'
132    } def
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 %% === La perspective inversee --------------------------------------------------
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 /pst-inverseperspective{
137   /Yp exch s@@y mul t@@y add def /Xp exch s@@x mul t@@x add def
138        Xp ua yH sub mul
139        Yp yH sub div   % x'
140        ua yH xD add mul ua xD add Yp mul sub
141        Yp  yH sub div  % y'
142    } def
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 %% === Les commandes -----------------------------------------------------------
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 /Image {
147   gsave
148     /showpage {} def
149     t@@x t@@y translate s@@x s@@y scale 
150     fichier run
151   grestore
152 } def

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.