Veranstaltung/Postscript Programming: Unterschied zwischen den Versionen
Aus LaborWiki
(+ Links) |
Marcus (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
(7 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
== | {{Veranstaltung | ||
|title=Programmieren in Postscript | |||
|actor=Daniel Otte | |||
|email= | |||
|url= | |||
|begin=2006/08/29 19:00:00 | |||
|place=LABOR e.V., Rottstr. 31, 44793 Bochum | |||
|contact= | |||
|audience= | |||
|tags= | |||
|type=talk | |||
|abstract= | |||
|image= | |||
|partof= | |||
}} | |||
__NOTOC__ | |||
==Teaser== | ==Teaser== | ||
Postscript kennen die meisten nur als Format für Drucker, dabei handelt es sich bei Postscript doch um eine mächtige Programmiersprache. | Postscript kennen die meisten nur als Format für Drucker, dabei handelt es sich bei Postscript doch um eine mächtige Programmiersprache. | ||
Zeile 14: | Zeile 24: | ||
*Das [http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF#search=%22Postscript%20Bluebook%22 Bluebook] | *Das [http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF#search=%22Postscript%20Bluebook%22 Bluebook] | ||
*[http://www.cs.indiana.edu/docproject/programming/postscript/postscript.html A First Guide to PostScript] | *[http://www.cs.indiana.edu/docproject/programming/postscript/postscript.html A First Guide to PostScript] | ||
==Code== | |||
<pre> | |||
%!PS | |||
/inch { 72 mul } def | |||
/mm { 2.8346456 mul } def | |||
/cm { 28.346456 mul } def | |||
/DIN_A_ratio { 2 sqrt } def | |||
/DIN_A_0 { 100 cm 100 cm mul DIN_A_ratio div sqrt dup DIN_A_ratio mul } def % A = 1 qm | |||
/DIN_A { % a -- x y a is the number of th DIN A, x and y are the corresponding sizes | |||
dup 0 eq | |||
{ pop DIN_A_0 } | |||
{ 1 sub DIN_A 2 div exch } ifelse | |||
} def | |||
/papersize { | |||
4 DIN_A | |||
} def | |||
/fontsize { 0.5 cm } def | |||
/lmargin { 2 cm } def | |||
/umargin { 1 cm } def | |||
/bmargin { 1 cm } def | |||
/init_page { | |||
papersize umargin sub fontsize sub lmargin exch | |||
moveto pop | |||
} def | |||
/newpage { showpage init_page } def | |||
/newline { | |||
currentpoint % -- x y | |||
fontsize 1.5 mul sub % -- x y_n | |||
dup bmargin ge % -- x y_n (y_n >= bmargin) | |||
{ lmargin exch moveto pop } { pop pop newpage } ifelse | |||
} def | |||
%--- MID | |||
/midx papersize pop 2 div def | |||
/midy papersize 2 div exch pop def | |||
/mid {midx midy} def | |||
%--- Colors | |||
/coloradd { % a b c x y z -- a+x b+y c+z | |||
% swap x & z // a b c z y x | |||
3 1 roll exch | |||
6 -1 roll add % // b c z y a+x | |||
3 1 roll % // b c a+x z y | |||
5 -1 roll add % // c a+x z b+y | |||
exch 4 -1 roll % // a+x b+y z c | |||
add | |||
} def | |||
/rgb-black {0 0 0} def | |||
/rgb-white {1 1 1} def | |||
/rgb-blue {0 0 1} def | |||
/rgb-green {0 1 0} def | |||
/rgb-red {1 0 0} def | |||
/rgb-yellow [rgb-red rgb-green coloradd] cvx def | |||
%----------- MAIN --------------------------------------- | |||
/smsize 5 cm def | |||
/smline smsize 20 div def | |||
/smmouthmid smsize 5 div 3 mul def | |||
/eyesize smsize 10 div def | |||
/eyexrel smsize 2.5 div def | |||
/eyeyrel smsize 2.5 div def | |||
smline setlinewidth | |||
rgb-yellow setrgbcolor | |||
newpath | |||
mid smsize 0 360 arc | |||
gsave | |||
fill | |||
grestore | |||
rgb-black setrgbcolor | |||
%newpath | |||
stroke | |||
% mouth | |||
newpath | |||
mid smmouthmid 0 180 arcn | |||
stroke | |||
% left eye | |||
mid eyeyrel add | |||
exch eyexrel sub exch | |||
newpath | |||
eyesize 0 360 arc fill | |||
% right eye | |||
mid eyeyrel add | |||
exch eyexrel add exch | |||
newpath | |||
eyesize 0 360 arc fill | |||
%showpage | |||
</pre> | |||
---- | |||
<pre> | |||
%!PS | |||
%--- calculate int-size | |||
1 1 | |||
{ | |||
exch 1 add exch | |||
1 bitshift | |||
dup 0 le {exit} if | |||
} loop | |||
dup | |||
/minint exch def | |||
not | |||
/maxint exch def | |||
/sizeofint exch def | |||
%--- END calculate int-size | |||
(\n\nBitsize:) print | |||
sizeofint 4 string cvs print | |||
(\nMaxInt:) print | |||
maxint 20 string cvs print | |||
(\nMinInt:) print | |||
minint 20 string cvs print | |||
%--- Big Num Stuff | |||
/intsInBig 5 def | |||
sizeofint 1 sub 2 log mul truncate dup | |||
cvi /decDigitsPerInt exch def | |||
10 exch exp cvi | |||
/innerRollOver exch def | |||
/newBig { [ intsInBig {0} repeat ] } def | |||
/newBig1 { [ intsInBig 1 sub {0} repeat 1] } def | |||
/addIntToBig { % int Big -- Big' | |||
} def | |||
/addBigBig { % Big Big -- Big | |||
aload pop intsInBig 1 add -1 roll | |||
aload pop | |||
% now we have a lot of ints on the stack | |||
/BigCarry false def % initial carry | |||
intsInBig { | |||
intsInBig index % copy other summand on stack | |||
add | |||
BigCarry { 1 add } if | |||
dup innerRollOver ge dup /BigCarry exch def | |||
{ innerRollOver sub} if | |||
intsInBig 2 mul 1 roll | |||
} repeat | |||
intsInBig array astore pop | |||
intsInBig array astore | |||
} def | |||
/Big2String { % Big -- Sting | |||
{ % we add a leading 1 to get the zeros | |||
innerRollOver add | |||
decDigitsPerInt 1 add string cvs | |||
1 decDigitsPerInt getinterval | |||
} forall | |||
% now we merge the substrings in one large string | |||
intsInBig array astore | |||
/tmpString decDigitsPerInt intsInBig mul cvi string def | |||
/tmpStringIndex 0 def | |||
{ | |||
tmpString tmpStringIndex 3 -1 roll putinterval | |||
/tmpStringIndex tmpStringIndex decDigitsPerInt add def | |||
} forall | |||
tmpString | |||
} def | |||
%--- END Big Num Stuff | |||
(\n\n) print | |||
(#############\n) print | |||
(# Fibonacci #\n) print | |||
(#############\n) print | |||
%0 1 | |||
%{ | |||
% dup 3 1 roll add | |||
% dup maxint gt {exit} if | |||
% dup = | |||
%} loop | |||
newBig newBig1 | |||
{ | |||
dup 3 1 roll addBigBig | |||
BigCarry {exit}if | |||
dup Big2String print (\n) print | |||
} loop | |||
% [0 0 0 0 0 0 0 1 ] [0 0 0 0 0 0 0 1 ] addBigBig pstack | |||
quit | |||
</pre> | |||
[[Kategorie:Veranstaltung]] |
Aktuelle Version vom 29. November 2014, 22:58 Uhr
Programmieren in Postscript | |
---|---|
Akteur | Daniel Otte |
Akteur Email | |
Akteur URL | |
Beginn | 2006/08/29 19:00:00 |
Ende | |
Ort | LABOR e.V., Rottstr. 31, 44793 Bochum |
Verantwortlich | |
Publikum | |
Schlagworte | |
Art | talk |
Rahmenveranstaltung | |
Export | iCalendar-Datei |
Kurzbeschreibung:
[Bearbeiten | Quelltext bearbeiten]
Postscript kennen die meisten nur als Format für Drucker, dabei handelt es sich bei Postscript doch um eine mächtige Programmiersprache. Diese Vortrag soll einen Einblick geben wie eine solche Stack-basierte Sprache funktioniert, wie sie bedient wird und was für Vor- und Nachteile sich daraus ergeben. Als Tools zum loslegen und mit-coden reicht ein Texteditor (z.B. vim) und ein Postscript-Viewer (empfehlenswert ist Ghostview).
Links[Bearbeiten | Quelltext bearbeiten]
- Die Spezifikationen von Adobe
- Das Bluebook
- A First Guide to PostScript
Code[Bearbeiten | Quelltext bearbeiten]
%!PS /inch { 72 mul } def /mm { 2.8346456 mul } def /cm { 28.346456 mul } def /DIN_A_ratio { 2 sqrt } def /DIN_A_0 { 100 cm 100 cm mul DIN_A_ratio div sqrt dup DIN_A_ratio mul } def % A = 1 qm /DIN_A { % a -- x y a is the number of th DIN A, x and y are the corresponding sizes dup 0 eq { pop DIN_A_0 } { 1 sub DIN_A 2 div exch } ifelse } def /papersize { 4 DIN_A } def /fontsize { 0.5 cm } def /lmargin { 2 cm } def /umargin { 1 cm } def /bmargin { 1 cm } def /init_page { papersize umargin sub fontsize sub lmargin exch moveto pop } def /newpage { showpage init_page } def /newline { currentpoint % -- x y fontsize 1.5 mul sub % -- x y_n dup bmargin ge % -- x y_n (y_n >= bmargin) { lmargin exch moveto pop } { pop pop newpage } ifelse } def %--- MID /midx papersize pop 2 div def /midy papersize 2 div exch pop def /mid {midx midy} def %--- Colors /coloradd { % a b c x y z -- a+x b+y c+z % swap x & z // a b c z y x 3 1 roll exch 6 -1 roll add % // b c z y a+x 3 1 roll % // b c a+x z y 5 -1 roll add % // c a+x z b+y exch 4 -1 roll % // a+x b+y z c add } def /rgb-black {0 0 0} def /rgb-white {1 1 1} def /rgb-blue {0 0 1} def /rgb-green {0 1 0} def /rgb-red {1 0 0} def /rgb-yellow [rgb-red rgb-green coloradd] cvx def %----------- MAIN --------------------------------------- /smsize 5 cm def /smline smsize 20 div def /smmouthmid smsize 5 div 3 mul def /eyesize smsize 10 div def /eyexrel smsize 2.5 div def /eyeyrel smsize 2.5 div def smline setlinewidth rgb-yellow setrgbcolor newpath mid smsize 0 360 arc gsave fill grestore rgb-black setrgbcolor %newpath stroke % mouth newpath mid smmouthmid 0 180 arcn stroke % left eye mid eyeyrel add exch eyexrel sub exch newpath eyesize 0 360 arc fill % right eye mid eyeyrel add exch eyexrel add exch newpath eyesize 0 360 arc fill %showpage
%!PS %--- calculate int-size 1 1 { exch 1 add exch 1 bitshift dup 0 le {exit} if } loop dup /minint exch def not /maxint exch def /sizeofint exch def %--- END calculate int-size (\n\nBitsize:) print sizeofint 4 string cvs print (\nMaxInt:) print maxint 20 string cvs print (\nMinInt:) print minint 20 string cvs print %--- Big Num Stuff /intsInBig 5 def sizeofint 1 sub 2 log mul truncate dup cvi /decDigitsPerInt exch def 10 exch exp cvi /innerRollOver exch def /newBig { [ intsInBig {0} repeat ] } def /newBig1 { [ intsInBig 1 sub {0} repeat 1] } def /addIntToBig { % int Big -- Big' } def /addBigBig { % Big Big -- Big aload pop intsInBig 1 add -1 roll aload pop % now we have a lot of ints on the stack /BigCarry false def % initial carry intsInBig { intsInBig index % copy other summand on stack add BigCarry { 1 add } if dup innerRollOver ge dup /BigCarry exch def { innerRollOver sub} if intsInBig 2 mul 1 roll } repeat intsInBig array astore pop intsInBig array astore } def /Big2String { % Big -- Sting { % we add a leading 1 to get the zeros innerRollOver add decDigitsPerInt 1 add string cvs 1 decDigitsPerInt getinterval } forall % now we merge the substrings in one large string intsInBig array astore /tmpString decDigitsPerInt intsInBig mul cvi string def /tmpStringIndex 0 def { tmpString tmpStringIndex 3 -1 roll putinterval /tmpStringIndex tmpStringIndex decDigitsPerInt add def } forall tmpString } def %--- END Big Num Stuff (\n\n) print (#############\n) print (# Fibonacci #\n) print (#############\n) print %0 1 %{ % dup 3 1 roll add % dup maxint gt {exit} if % dup = %} loop newBig newBig1 { dup 3 1 roll addBigBig BigCarry {exit}if dup Big2String print (\n) print } loop % [0 0 0 0 0 0 0 1 ] [0 0 0 0 0 0 0 1 ] addBigBig pstack quit