2009/11/18

PostScript 外部ファイル読み込み

%!PS-Adobe-3.0
123

%!PS-Adobe-3.0

/Times-Roman findfont 100 scalefont setfont
200 200 moveto
(sample.ps) run
3 string cvs show
showpage

PostScript 繰り返し

 

%!PS-Adobe-3.0
% P.30 2.9.2 回数による繰り返し
/power {
    3 dict begin
        /i exch def
        /n exch def
        /p 1 def
        i {
            /p p n mul def
        } repeat
        p
    end
} def

3 4 power == % 81

%!PS-Adobe-3.0
% P.30 2.9.3 制御変数による繰り返し
% 引数の全ての約数を出力する

/divisor {
    mod 0 eq
} def

/alldivisors {
    2 dict begin
        /max exch def
        1 1 max {
            /i exch def
            max i divisor {
                i ==
            } if
        } for
    end
} def

%!PS-Adobe-3.0
% P.31 2.9.4 条件による繰り返し

% 最大公約数を求める(ユークリッドの互助法)
%     ステップ1 与えられた二つの整数のそれぞれをn とm とする。
%     ステップ2 m が0 ならば計算を終了する。
%     ステップ3 n をm で除算したあまりをr とする。
%     ステップ4 m をn とする。
%     ステップ5 r をm とする。
%     ステップ6 ステップ2 に戻る。

/gcm {
    3 dict begin
        /m exch def
        /n exch def
        {
            m 0 eq {
                exit
            } if
            /r n m mod def
            /n m def
            /m  r def
        } loop
        n
    end
} def

54 36 gcm == % 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 で詳細を見る