Veranstaltung/Postscript Programming: Unterschied zwischen den Versionen

Aus LaborWiki
Wechseln zu: Navigation, Suche
(+ Links)
(+ smilie sample)
Zeile 14: Zeile 14:
*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==
%!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

Version vom 29. August 2006, 19:54 Uhr

Facts

  • Was: Programmieren in Postscript
  • Wann: 29.08.2006
  • Wo: im Labor (wo sonst?)
  • Wer: Daniel

Teaser

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

Code

%!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