| 1 |
%% $Id: pstricks-add.pro 216 2021-09-10 12:28:13Z herbert $ |
| 2 |
%% |
| 3 |
% PostScript prologue for pstricks-add.tex. |
| 4 |
% |
| 5 |
% Version 0.23, 2009/12/17 |
| 6 |
% |
| 7 |
/tx@addDict 410 dict def tx@addDict begin |
| 8 |
%% |
| 9 |
realtime srand % set random generator |
| 10 |
% |
| 11 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 12 |
/GTriangle { |
| 13 |
gsave |
| 14 |
/mtrx CM def |
| 15 |
/colorA ED /colorB ED /colorC ED % save the colors |
| 16 |
/yA ED /xA ED % save the origin |
| 17 |
xA yA translate |
| 18 |
rotate % \psk@gangle |
| 19 |
/yB ED /xB ED /yC ED /xC ED % save other coordinates |
| 20 |
/ds [ % save data in a array |
| 21 |
0 0 0 colorA aload pop % fd x y xr xg xb |
| 22 |
0 xB xA sub yB yA sub colorB aload pop |
| 23 |
0 xC xA sub yC yA sub colorC aload pop |
| 24 |
% 1 xC xB add yB colorA aload pop % for use with 4 points ABCD |
| 25 |
] def |
| 26 |
newpath |
| 27 |
<< |
| 28 |
/ShadingType 4 % single Gouraud |
| 29 |
/ColorSpace [ /DeviceRGB ] |
| 30 |
/DataSource ds |
| 31 |
>> |
| 32 |
shfill |
| 33 |
closepath |
| 34 |
mtrx |
| 35 |
setmatrix grestore} def |
| 36 |
% |
| 37 |
/RGBtoCMYK { % on stack r g b -> C M Y K |
| 38 |
3 dict begin |
| 39 |
/Blue ED /Green ED /Red ED |
| 40 |
1 Red sub % Cyan |
| 41 |
1 Green sub % Magenta |
| 42 |
1 Blue sub % Yellow |
| 43 |
0 % Black |
| 44 |
end |
| 45 |
} def |
| 46 |
% |
| 47 |
/CMYKtoGRAY { % on stack c m y k -> gray |
| 48 |
exch 0.11 mul add |
| 49 |
exch 0.59 mul add |
| 50 |
exch 0.3 mul add |
| 51 |
dup 1 gt { pop 1 } if |
| 52 |
neg 1 add |
| 53 |
} def |
| 54 |
% |
| 55 |
/RGBtoGRAY { % on stack r g b -> gray |
| 56 |
0.11 mul |
| 57 |
exch 0.59 mul add |
| 58 |
exch 0.3 mul add |
| 59 |
} def |
| 60 |
% |
| 61 |
/HSBtoGRAY { |
| 62 |
6 dict begin |
| 63 |
/b exch def |
| 64 |
/s exch def 6 mul dup cvi dup |
| 65 |
/i exch def sub |
| 66 |
/f exch def |
| 67 |
/F [[0 1 f sub 1][f 0 1][1 0 1 f sub][1 f 0][1 f sub 1 0][0 1 f][0 1 1]] def |
| 68 |
F i get { s mul neg 1 add b mul} forall |
| 69 |
0.11 mul |
| 70 |
exch 0.59 mul add |
| 71 |
exch 0.3 mul add |
| 72 |
end |
| 73 |
} def |
| 74 |
% |
| 75 |
%% convertisseur longueur d'onde ->R,G,B Manuel Luque |
| 76 |
%% lambda max=780 nanometres |
| 77 |
%% lambda min=380 nanometres |
| 78 |
%% adaptation de : |
| 79 |
%% http://www.physics.sfasu.edu/astro/color.html |
| 80 |
%% www.efg2.com/lab |
| 81 |
% |
| 82 |
/Gamma 0.8 def |
| 83 |
|
| 84 |
/calculateRGB { |
| 85 |
lambda 379 le {/Red 0 def /Green 0 def /Blue 0 def} if |
| 86 |
lambda 781 ge {/Red 0 def /Green 0 def /Blue 0 def} if |
| 87 |
lambda 380 ge {lambda 439 le { |
| 88 |
/R {lambda 440 sub neg 440 380 sub div} def |
| 89 |
/Red R factor mul Gamma exp def |
| 90 |
/G 0 def |
| 91 |
/Green G factor mul Gamma exp def |
| 92 |
/B 1 def |
| 93 |
/Blue B factor mul Gamma exp def} if |
| 94 |
} if |
| 95 |
lambda 440 ge { lambda 489 le { |
| 96 |
/G {lambda 440 sub 490 440 sub div} def |
| 97 |
/Green G factor mul Gamma exp def |
| 98 |
/R 0 def /Red 0 def |
| 99 |
/B 1 def |
| 100 |
/Blue B factor mul Gamma exp def } if |
| 101 |
} if |
| 102 |
lambda 490 ge {lambda 509 le { |
| 103 |
/B {lambda 510 sub neg 510 490 sub div} def |
| 104 |
/Blue B factor mul Gamma exp def |
| 105 |
/R 0 def /Red 0 def |
| 106 |
/G 1 def |
| 107 |
/Green G factor mul Gamma exp def } if |
| 108 |
} if |
| 109 |
lambda 510 ge {lambda 579 le { |
| 110 |
/R {lambda 510 sub 580 510 sub div } def |
| 111 |
/Red R factor mul Gamma exp def |
| 112 |
/Blue 0 def |
| 113 |
/G 1 def |
| 114 |
/Green G factor mul Gamma exp def } if |
| 115 |
} if |
| 116 |
lambda 580 ge {lambda 644 le { |
| 117 |
/G {lambda 645 sub neg 645 580 sub div } def |
| 118 |
/Green G factor mul Gamma exp def |
| 119 |
/Blue 0 def |
| 120 |
/R 1 def |
| 121 |
/Red R factor mul Gamma exp def } if |
| 122 |
} if |
| 123 |
lambda 645 ge { lambda 780 le { |
| 124 |
/Red 1 factor mul Gamma exp def |
| 125 |
/Blue 0 def |
| 126 |
/Green 0 def } if |
| 127 |
} if |
| 128 |
} def |
| 129 |
% |
| 130 |
/factor { |
| 131 |
lambda 380 ge {lambda 419 le { 0.3 0.7 lambda 380 sub mul 420 380 sub div add} if } if |
| 132 |
lambda 420 ge {lambda 700 le { 1 } if } if |
| 133 |
lambda 701 ge {lambda 780 le { 0.3 0.7 780 lambda sub mul 780 700 sub div add} if } if |
| 134 |
} def |
| 135 |
% |
| 136 |
/wavelengthToRGB { % the wavelength in nm must be on top of the stack |
| 137 |
cvi /lambda exch def % no floating point here |
| 138 |
calculateRGB |
| 139 |
} def % now the colors are saved in Red Green Blue |
| 140 |
% |
| 141 |
/wavelengthToGRAY { % the wavelength in nm must be on top of the stack |
| 142 |
cvi /lambda exch def % no floating point here |
| 143 |
calculateRGB |
| 144 |
Red Green Blue RGBtoGRAY |
| 145 |
} def % now the gray color is on the stack |
| 146 |
% |
| 147 |
/wavelengthToCMYK { % the wavelength in nm must be on top of the stack |
| 148 |
cvi /lambda exch def % no floating point here |
| 149 |
gsave |
| 150 |
calculateRGB Red Green Blue RGBtoCMYK |
| 151 |
/Black ED /Yellow ED /Magenta ED /Cyan ED |
| 152 |
grestore |
| 153 |
} def % now the colors are saved in Cyan Magenta Yellow Black |
| 154 |
% |
| 155 |
/axfill { |
| 156 |
8 dict begin |
| 157 |
/xw exch def /nl exch def |
| 158 |
/C1 exch def /y1 exch def/x1 exch def |
| 159 |
/C0 exch def /y0 exch def/x0 exch def |
| 160 |
<< /ShadingType 2 |
| 161 |
/ColorSpace /DeviceRGB |
| 162 |
/Coords [ x0 y0 x1 y1 ] |
| 163 |
/EmulatorHints [ xw 2 div dup ] |
| 164 |
/Function << |
| 165 |
/FunctionType 2 |
| 166 |
/Domain [0 1] |
| 167 |
/C0 C0 |
| 168 |
/C1 C1 |
| 169 |
/N 1 |
| 170 |
>> |
| 171 |
>> shfill |
| 172 |
end |
| 173 |
} bind def |
| 174 |
% |
| 175 |
%/amplHand {.8} def |
| 176 |
%/dtHand 2 def |
| 177 |
/varHand { rand sin amplHand mul add } def |
| 178 |
/MovetoByHand { moveto } def |
| 179 |
%/MovetoByHand { /y0 ED /x0 ED x0 y0 moveto } def |
| 180 |
/LinetoByHand { 4 dict begin |
| 181 |
/y1 ED /x1 ED |
| 182 |
currentpoint /y0 ED /x0 ED |
| 183 |
x0 x1 sub dup mul y0 y1 sub dup mul add sqrt /dEnd ED |
| 184 |
0 dtHand dEnd { dup |
| 185 |
x1 x0 sub mul dEnd div x0 add varHand exch |
| 186 |
y1 y0 sub mul dEnd div y0 add varHand lineto |
| 187 |
} for |
| 188 |
% /x0 x1 def /y0 y1 def |
| 189 |
end |
| 190 |
} def |
| 191 |
% |
| 192 |
end |
| 193 |
% |
| 194 |
% END pstricks-add.pro |