2009/11/18

PostScript 高階手続き

 

%!PS-Adobe-3.0
% P.35 2.11 高階手続き
% higher order procedure

/twice {
    1 dict begin
        /proc exch def
        proc proc
    end
} def

{ (KPF) == } twice % (KPF)(KPF)

/sum {
    2 dict begin
        /f exch def
        /n exch def
        n 1 eq {
            1 f
        } {
            n 2 ge {
                n f
                n 1 sub
                /f load
                sum add
            } {
                (undefined)
            } ifelse
        } ifelse
    end
} def

10 { } sum == % 55
10 { dup mul } sum == % 385
10 { dup dup mul mul }  sum == % 3025

PostScript 述語の定義

 

%!PS-Adobe-3.0
% P.27 2.7.6 述語の定義
% 3つの引数が全て等しいかどうかを判定

/triple {
    3 dict begin
        /any1 exch def
        /any2 exch def
        /any3 exch def
        any1 any2 eq any1 any3 eq and
    end
} def

1 1 1 triple == % true
1 2 1 triple == % false
1 1 3 triple == % false
1 2 3 triple == % false

2009/11/17

PostScript dict

GS>/thestring (global) def
GS>thestring =
global
GS>/exampledict 1 dict def
GS>exampledict begin
GS>thestring =
global
GS>/thestring (local) def
GS>thestring =
local
GS>end
GS>thestring =
global
GS>

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

PostScript Expanded and constant width lines, matrix

Program02-ExpandedAndConstantWidthLines.ps

% Expanded and constant width lines
% BlueBook P.136 - 137

% --- procedures -----------------------
/pow {
    /n 1.75 def
    2 {
        n mul
        exch
    } repeat
} def

/inch {
    72 mul
} def

/centersquare {
    .5 .5 pow moveto
    -.5 .5 pow lineto
    -.5 -.5 pow lineto
    .5 -.5 pow lineto
    closepath
} def

/tran {
    /proc exch def
    /proc load
    gsave
    proc
    grestore
} def

% --- main -----------------------------
{
    2.5 inch 6 inch translate
    1 16 div setlinewidth
    1 1 5 {
        {
            pop .5 mul inch dup scale
            centersquare
            stroke
        } tran
    } for
} tran

{
    6 inch 6 inch translate
    1 setlinewidth
    /cmtx matrix currentmatrix def
    1 1 5 {
        {
            pop .5 mul inch dup scale
            centersquare
            cmtx setmatrix
            stroke
        } tran
    } for
} tran

showpage

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

PostScript Repeated Shapes

Program01-RepeatedShapes.ps

% Repeated Shapes
% BlueBook P.134 - 135

% --- variables ------------------------
/power 1.75 def

% --- procedures -----------------------
/tran {
    /proc exch def
    /proc load
    gsave
    proc
    grestore
} def

/inch {
    72 mul power mul
} def

/wedge {
    newpath
    0 0 moveto
    1 0 translate
    15 rotate
    0 15 sin translate
    0 0 15 sin -90 90 arc
    closepath
} def

% --- main -----------------------------
{
    1 inch 1 inch translate
    1 inch 1 inch scale
    wedge 0.02 setlinewidth
    stroke
} tran

-225 0 translate

{
    4.25 inch dup translate
    1.75 inch dup scale
    0.02 setlinewidth
    1 1 12 {
        12 div setgray
        {
            wedge
            {
                fill
            } tran
            0 setgray
            stroke
        } tran
        30 rotate
    } for
} tran

showpage

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

PostScript The Image Operator - Helicopter

WS0824 11.1-TheImageOperator-Helicopter.ps

WS0824

% --- variables ------------------------
/xpos 50 def
/ypos 750 def
/xscale 72 def
/yscale 72 def
/col-width 72 def
/line-hight 72 def
/bottom-limit 10 def

% --- procedure ------------------------
/transact {
    gsave
    /proc exch def
    /proc load
    proc
    grestore
} def

/newline {
    currentpoint line-hight sub moveto
    currentpoint exch pop bottom-limit lt {
        /xpos xpos col-width add def
        xpos ypos moveto
    } if

} def

% --- main -----------------------------
/Times-Roman findfont 30 scalefont setfont
xpos ypos moveto

1 1 77 {
    {
        currentpoint translate
        xscale yscale scale
        pop 7 mod 0 ne {
            1
        } {
            2
        } ifelse
        8 exch 8 exch [8 0 0 8 0 0] {
            <c936>
        } image
    } transact
    newline
} for

% 00110110
% 11001001
% 00110110
% 11001001
% 00110110
% 11001001
% 00110110
% 11001001

showpage

 

11.1-TheImageOperator-Helicopter.ps

/Helicopter <dd ff 00 ff 54 1f 80 03 fb f9 00 1e> def

100 300 translate
450 450 scale

16 6 1 [16 0 0 6 0 0] {
    Helicopter
} image

showpage

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

2009/11/13

PostScript CharactorOutlines, load, charpath

9.4-CharacterOutline.ps

% --- variables ------------------------
/font-size 45 def
/Helvetica-Bold findfont font-size scalefont setfont
/message (9LISP) def
/title (Kyushu.lisp@KPF) def

% --- procedures -----------------------
/oshow {
    true charpath stroke
} def

/circleofString {
    /angle exch def
    /slope exch def
    /show-proc exch def
    /show-proc load

    15 angle 345 {
        gsave
        rotate
        slope 0 moveto
        message show-proc
        grestore
    } for
} def

/draw-title {
    0 0 moveto
    title true charpath
    gsave
    1 setgray fill
    grestore
} def

% --- main -----------------------------
165 600 translate
.5 setlinewidth

{ show } 30 45 circleofString

draw-title
stroke

0 -400 translate
.5 setlinewidth

{ oshow } 10 13 circleofString

draw-title
stroke

showpage

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

PostScript clip, charpath

10.1-ClippintPath.ps 10.1-ClippintPath-2.ps

10.1-ClippintPath.ps

% --- procedures -----------------------
/inc {
    3 mul
} def
/trianglepath {
    newpath
    0 0 moveto
    144 inc 0 lineto
    72 inc 200 inc lineto
    closepath
} def

/verticals {
    newpath
    0 9 144 inc {
        0 moveto
        0 216 inc rlineto
    } for
    stroke
} def

/horizontals {
    newpath
    0 10 200 inc {
        0 exch moveto
        144 inc 0 rlineto
    } for
    stroke
} def

% --- main -----------------------------
100 100 translate
gsave
trianglepath clip
3 setlinewidth
verticals
horizontals
grestore
verticals
horizontals

showpage

 

10.1-ClippintPath-2.ps

% --- variables ------------------------
/line-height 90 def
/font-size 95 def
/Times-BoldItalic findfont font-size scalefont setfont

% --- procedures -----------------------
/newline {
    currentpoint line-height sub
    exch pop 0
    exch moveto
} def

/rays {
    0 .3 300 {
        gsave
        rotate
        0 0 moveto
        512 -750 lineto
        stroke
        grestore
    } for
} def

% --- main -----------------------------
30 400 translate
.5 setlinewidth

newpath
0 0 moveto

(Kumamoto) true charpath
newline
(Programming) true charpath
newline
(Freaks) true charpath
clip

newpath
-120 -20 translate
rays

showpage

 

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

PostScript Line-Drawing Details, setdash, aload, astore, roll

10.2-LineDrawingDetails.ps

% --- variables ------------------------
/width 500 def
/height 700 def
/ypos 700 def
/font-size 15 def
/dec-point 15 def
/Times-Roman findfont font-size scalefont setfont

% --- procedures -----------------------
/prt-n {
    (   ) cvs show
} def

/borders {
    -2.5 0 moveto
    0 height rlineto
    width 0 moveto
    0 height rlineto
    stroke
} def

/newline {
    /ypos ypos dec-point sub def
} def

/doLine {
    0 ypos moveto
    width 0 rlineto
    stroke
    5 ypos 2 add moveto
    ypos prt-n
    newline
} def

/dot {
    setdash doLine
} def

% --- main -----------------------------
50 50 translate
15 setlinewidth
borders

.5 setlinewidth
[] 0 dot
/dotary [0 1 2 3 4 5] def
height dec-point idiv {
    /dotary dotary aload pop 6 1 roll 6 array astore def
    [4 4] dotary 0 get dot
} repeat

showpage

 

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る

PostScript FontTransformations, makefont, newline

9.3-FontTransformations.ps 

% --- variables ------------------------
/basefont /Times-Roman findfont def
/LM 72 def
/line-height 53 def

% --- procedures -----------------------
/newline {
    currentpoint line-height sub
    exch pop LM
    exch moveto
} def

/up {
    40 add
} def

% --- main -----------------------------
LM 600 moveto

basefont [12 up 0 0 12 up 0 0] makefont setfont
("Talking of axes,") show newline

basefont [17 up 0 0 12 up 0 0] makefont setfont
(said the Duchess,) show newline

basefont [7 up 0 0 12 up 0 0] makefont setfont
("Off with her head!") show newline

basefont [12 up 0 6.93 up 12 up 0 0] makefont setfont
(        - Lewis Carrol) show
showpage

 

PostScript(R) Language Tutorial and Cookbook (APL)

PostScript(R) Language Tutorial and Cookbook (APL)

posted with amazlet at 09.10.07

Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 235737

おすすめ度の平均: 5.0

5 まず最初に読むべき入門書
5 効率の良いPostScript書くなら…

Amazon.co.jp で詳細を見る