2009/11/12

PostScript 条件分岐

7.1-ConditionExecution-1.ps
% ---variables---------------------------------------------
/LM 72 def
/RM 212 3 mul def
/ypos 720 def
/lineheight 40 def

% ---procedures--------------------------------------------
/newline{
    ypos lineheight sub
    /ypos exch def
    LM ypos moveto
} def

/prtstr{
    dup stringwidth pop
    currentpoint pop
    add RM
gt
    {newline} if
    show
} def

/choosefont{
    exch findfont exch scalefont setfont
} def

% ---main program------------------------------------------
/Times-Italic findfont 50 scalefont setfont
LM ypos moveto
(If ) prtstr
(you ) prtstr
(tell ) prtstr
(the ) prtstr
(truth, ) prtstr
(you ) prtstr
(don't ) prtstr
(have ) prtstr
(to ) prtstr
(remember ) prtstr
(anything. ) prtstr
(- Mark ) prtstr
(Twain ) prtstr

showpage
7.1-ConditionExecution-2.ps
% --- variables ----------------------------------------
/scalefactor 1 def
/counter 0 def

% --- procedures ---------------------------------------
/DecreaseScale {
    scalefactor .2 sub
    /scalefactor exch def
} def

/IncreaseConter {
    /counter counter 1 add def
} def

/trappath {
    0 0 moveto
    90 0 rlineto
    -20 45 rlineto
    -50 0 rlineto
    closepath
} def

/doATrap {
    gsave
    1 scalefactor scale
    trappath
    counter 2 mod
    0 eq {.5} {0} ifelse
    setgray fill
    grestore
} def

% --- programs -----------------------------------------
0 0 moveto
250 350 translate

10 {
    IncreaseConter
    doATrap
    DecreaseScale
    0 20 translate
} repeat

showpage

  • eq =
  • ne ≠
  • gt >
  • lt <
  • ge >=
  • le <=

0 件のコメント:

コメントを投稿