ラベル PostScript の投稿を表示しています。 すべての投稿を表示
ラベル PostScript の投稿を表示しています。 すべての投稿を表示

2013/12/31

@golden_lucky「PostScriptは年賀状を書くための言語です」

@golden_luckyさんのPostScript年賀状を勝手にまとめた。2012, 2008が好きです。

2010/12/30

Emacs で GhostScript(PostScript)

そういえばメモってなかったので。

ps-mode を load して、ps-run-x に GhostScript のパスを指定すれば OK 。
ps-mode で C-c C-s すれば GhostScript の REPL が出てくる。

;; ps-mode
;; C-c C-v : ps-run-boundingbox
;; C-c C-u : ps-mode-uncomment-region
;; C-c C-t : ps-mode-epsf-rich
;; C-c C-s : ps-run-start
;; C-c C-r : ps-run-region
;; C-c C-q : ps-run-quit
;; C-c C-p : ps-mode-print-buffer
;; C-c C-o : ps-mode-comment-out-region
;; C-c C-k : ps-run-kill
;; C-c C-j : ps-mode-other-newline
;; C-c C-l : ps-run-clear
;; C-c C-b : ps-run-buffer
(load "ps-mode")
(setq ps-run-x `(,(expand-file-name "~/gs-path")))

逆ポーランド記法の言語といえば Forth ですが、Forth 使いの人の呼び名がかっこいいです。

ページ記述言語 PostScriptチュートリアル&クックブック (ASCII電子出版シリーズ)

2010/04/18

邪悪なPostScriptコード


%!OPS-1.0 %%Creator: HAYAKAWA,Takashi
/A/copy/p/floor/q/gt/S/add/n/exch/i/index/J/ifelse/r/roll/w/div/H{{loop}stopped
Y}def/t/and/C/neg/T/dup/h/exp/Y/pop/d/mul/s/cvi/e/sqrt/R/rlineto{load def}H 300
T translate(V2L&1i2A00053r45hNvQXz&vUX&UOvQXzFJ!FJ!J!O&Y43d9rE3IaN96r63rvx2dcaN
G&140N7!U&4C577d7!z&&93r6IQO2Z4o3AQYaNlxS2w!!f&nY9wn7wpSps1t1S!D&cjS5o32rS4oS3o
Z&blxC1SdC9n5dh!I&3STinTinTinY!B&V0R0VRVC0R!N&3A3Axe1nwc!l&993dC99Cc96raN!a&1CD
E&YYY!F&&vGYx4oGbxSd0nq&3IGbxSGY4Ixwca3AlvvUkbQkdbGYx4ofwnw!&vlx2w13wSb8Z4wS!J!
c&j1idj2id42rd!X&4I3Ax52r8Ia3A3Ax65rTdCS4iw5o5IxnwTTd32rCST0q&eCST0q&D1!&EYE0!J
&EYEY0!J0q!x&jd5o32rd4odSS!K&WCVW!Q&31C85d4!k&X&E9!&1!J!v&6A!b&7o!o&1r!j&43r!W)
{( )T 0 4 3 r put T(/)q{T(9)q{cvn}{s}J}{($)q{[}{]}J}J cvx}forall 270{def}H
K{K{L setgray moveto B fill}for Y}for showpage

邪悪過ぎませんか・・・。

私も、PostScriptはちょっぴり書くことがあるのですが、とても読めません・・・。そもそも読めるようなものなんでしょうか・・・。
%!PS-Adobe-3.0 
% factorial

/fact { 
    1 dict begin 
        /n exch def 
        n 1 eq n 0 eq or { 
            1 
        } { 
            n 1 sub fact n mul 
        } ifelse 
    end 
} def

5 fact % 120

gif

こっちもすごいなぁ。gifにできるんですね。


%!PS-Adobe-3.0
%%BoundingBox: 0 0 100 20
%%Title: orz.ps
%%Creator: @aka
%%CreationDate: Thu May 19 23:06:30 2005
%%EndComments

64 dict begin

/dots 14 def
/Helvetica-Bold findfont 18 scalefont setfont

/orz {
  0 1 dots {
    /head exch def
    0 0 moveto
    dots head sub { (.) show } repeat
    (o) show
    head { (.) show } repeat
    (rz) show
    showpage
  } for
} def

orz

end
showpage
%%EOF

9LISP

9LISPでは、LOLの「第7章 Lispを動かすForthを動かすLisp」を参考にPostScriptを実装してみたい、というのも当面の目標の一つです。最終的にはS式で書けるPostScript的な何かができたら良いなーなどと。

たまには、スタック指向な言語もいかがですか。

関連


PostScriptリファレンスマニュアル第3版 (ASCII電子出版シリーズ)
Adobe Systems
アスキー
売り上げランキング: 332789
おすすめ度の平均: 4.5
4 端から端まで読む本ではありませんが
5 待ってました
5 PostScript開発者必携本です!
PostScript & Acrobat/PDF
PostScript & Acrobat/PDF
posted with amazlet at 10.04.18
トーマス マーツ
東京電機大学出版局
売り上げランキング: 1059666
おすすめ度の平均: 4.0
4 画像処理関係の開発者にお勧め

2010/04/07

P.S ってPostscriptの略だったんですか、そうですか。

この方のブログ、Google Alertによく引っかかるので以前から存じてはいました。PostScript(プログラミング言語)に何かしらの思い入れでもあるんだろうか、などと思っていました。

先ほどTwitterで教えて頂いたのですが、PostscriptってあのPSなんですね。手紙のP.S。追伸ってことですか。そうですか。
逆ポーランド記法でスタック指向なPostScriptを、LotYなどにどうでしょうか。
実はこのブログにも一つのカテゴリがあります(笑)

2009/12/02

PostScript 書籍 PDF 追加

 

PostScript(R) Language Program Design (APL)
Adobe Systems Inc.
Addison-Wesley Professional
売り上げランキング: 59322

 

BlueBook, Thinking in PostScript 他はこちら

2009/11/19

PostScript DSCコメント, ページ, page

 

%!PS-Adobe-3.0
%%Pages: 3

% PostScript実習マニュアル
% P.70 DSC

% %%Title
% %%EOF
% %%Page
% %%Pages
% %%BoundingBox

% P.71 page.ps
/showstring {
    1 dict begin
        /string exch def
        100 500 moveto
        0 0.6 0 setrgbcolor
        /Times-Roman findfont 128 scalefont setfont
        string show
        showpage
    end
} def

%%Page: (first page) 1
(first) showstring
%%Page: (second page) 2
(second) showstring
%%Page: (third page) 3
(third) showstring

 

そうそう、2ページ目以降ってどうやるんだろうって思ってたんだった。この方法だけなのかな。

PostScript gsave grestore

gsave-grestore.ps

 

 

%!PS-Adobe-3.0
% PostScript実習マニュアル
% P.68 3.11 グラフィックス状態の保存

/square {
    2 dict begin
        /y exch def
        /x exch def
        x y moveto
        200 0 rlineto
        0 200 rlineto
        -200 0 rlineto
        fill
    end
} def

/specialsquare {
    gsave
        200 200 translate
        50 rotate
        2 0.5 scale
        0.4 0.8 0 setrgbcolor
        0 0 square
    grestore
} def

0 0.4 0.8 setrgbcolor
200 100 square
specialsquare
200 500 square
showpage

 

 

PostScript Clip Star

clip-star.ps

 

 

%!PS-Adobe-3.0
% PostScript実習マニュアル
% P.67 3.10 クリッピング

% clip
% eoclip
% initclip

/star {
    2 dict begin
        /y exch def
        /x exch def
        newpath
        x y moveto
        300 0 rlineto
        -250 -200 rlineto
        100 300 rlineto
        100 -300 rlineto
    end
} def

/polkadot {
    4 dict begin
        /y exch def
        /x exch def
        /dy y def
        14 {
            /dy dy 25 add def
            /dx x def
            14 {
                /dx dx 25 add def
                newpath
                dx dy 8 0 360 arc
                stroke
            } repeat
        } repeat
    end
} def

/polkadotstar {
    150 650 star
    clip
    100 400 polkadot
} def

/polkadotstarbyeo {
    150 300 star
    eoclip
    100 50 polkadot
} def

1 0 0.4 setrgbcolor
6 setlinewidth
polkadotstar
initclip
polkadotstarbyeo
showpage

 

 

PostScript ベジェ曲線

bezier-1.ps bezier-2.ps

 

bezier-1.ps

%!PS-Adobe-3.0
% PostScript実習マニュアル
% P.58 3.7 ベジェ曲線

% P.58 3.7.1 ベジェ曲線の基礎
/bezier {
    8 dict begin
        /y3 exch def
        /x3 exch def
        /y2 exch def
        /x2 exch def
        /y1 exch def
        /x1 exch def
        /y0 exch def
        /x0 exch def
        newpath
        x0 y0 moveto
        x1 y1 x2 y2 x3 y3 curveto
        0 0.8 1 setrgbcolor
        40 setlinewidth
        stroke
        newpath
        x0 y0 moveto
        x1 y1 lineto
        x2 y2 moveto
        x3 y3 lineto
        1 0 0 setrgbcolor
        1 setlinewidth
        stroke
    end
} def

140 450 100 650 500 750 300 450 bezier
140 150 100 350 300 150 500 450 bezier
showpage

bezier-2.ps

%!PS-Adobe-3.0
% PostScript実習マニュアル
% P.58 3.7 ベジェ曲線

% P59 3.7.3 ベジェ曲線の連結
/bezbez {
    14 dict begin
        /y6 exch def
        /x6 exch def
        /y5 exch def
        /x5 exch def
        /y4 exch def
        /x4 exch def
        /y3 exch def
        /x3 exch def
        /y2 exch def
        /x2 exch def
        /y1 exch def
        /x1 exch def
        /y0 exch def
        /x0 exch def
        newpath
        x0 y0 moveto
        x1 y1 x2 y2 x3 y3 curveto
        x4 y4 x5 y5 x6 y6 curveto
        0 1 0.8 setrgbcolor
        30 setlinewidth
        stroke
        newpath
        x0 y0 moveto
        x1 y1 lineto
        x2 y2 moveto
        x3 y3 lineto
        1 0 0 setrgbcolor
        1 setlinewidth
        stroke
        newpath
        x3 y3 moveto
        x4 y4 lineto
        x5 y5 moveto
        x6 y6 lineto
        0 0 1 setrgbcolor
        stroke
    end
} def

150 600 100 750 350 700 250 600 300 450 500 400 400 600 bezbez
150 300 100 450 350 400 250 300 100 150 500 100 400 300 bezbez
showpage

 

  • PostScript実習マニュアル
  • PostScript - PDF,Web まとめ
  • PostScript 日本語フォント

     

    PostScript実習マニュアル
    P.63 3.8.10 日本語のフォント

    Ryumin-Light-RKSJ-H 明朝体の横組み。
    Ryumin-Light-RKSJ-V 明朝体の縦組み。
    GothicBBB-Medium-RKSJ-H ゴシック体の横組み。
    GothicBBB-Medium-RKSJ-V ゴシック体の縦組み。

    ちなみに、これらのフォント名を持つフォント辞書は、文字コードとしてShift JIS を使っています。これらのフォント名に含まれているRKSJ という部分をEUC に置き換えると、文字コードとしてEUC-JP を使うフォント辞書の名前になります。

    2009/11/18

    PostScript 色, setrgbcolor, setcmykcolor, setgray, 線, setlinecap, setlinejoin, setlinemilter, setdash

    setrgbcolor.pscmykcolor.ps setgray.ps cap.psjoin.psmiter.ps dash.ps rowdash.ps

     

     setrgbcolor.ps

    % P.50 3.4 色 3.4.2 加法混色
    % red green blue setrgbcolor

    % rgb
    /hline {
        5 dict begin
            /blue exch def
            /green exch def
            /red exch def
            /y exch def
            /x exch def
            newpath
            x y moveto
            30 0 rlineto
            30 setlinewidth
            red green blue setrgbcolor
            stroke
        end
    } def

    /hundredlines {
        4 dict begin
            /red 0 def
            300 40 660 {
                /y exch def
                /green 0 def
                100 40 460 {
                    /x exch def
                    x y red green 0 hline
                    /green green 0.1 add def
                } for
                /red red 0.1 add def
            } for
        end
    } def
    hundredlines
    showpage

    cmykcolor.ps 

    % P.51 3.4.3 減法混色
    % cyan magenta yellow black setcmykcolor

    /hline {
        6 dict begin
            /black exch def
            /yellow exch def
            /magenta exch def
            /cyan exch def
            /y exch def
            /x exch def
            newpath
            x y moveto
            30 0 rlineto
            30 setlinewidth
            cyan magenta yellow black setcmykcolor
            stroke
        end
    } def

    /hundredlines {
        4 dict begin
            /cyan 0 def
            300 40 660 {
                /y exch def
                /magenta 0 def
                100 40 460 {
                    /x exch def
                    x y cyan magenta 0 0 hline
                    /magenta magenta 0.1 add def
                } for
                /cyan cyan 0.1 add def
            } for
        end
    } def
    hundredlines
    showpage

    setgray.ps

    % setgray
    /dline {
        newpath
        150 100 moveto
        300 600 rlineto
        40 setlinewidth
        stroke
    } def

    /hline {
        2 dict begin
            /gray exch def
            /y exch def
            newpath
            100 y moveto
            400 0 rlineto
            30 setlinewidth
            gray setgray
            stroke
            end
    }def

    /elevenlines {
        3 dict begin
            /gray 0 def
            200 40 600 {
                /y exch def
                y gray hline
                /gray gray 0.1 add def
            } for
        end
    } def

    dline
    elevenlines
    showpage

    cap.ps

    % cap
    /hline {
        2 dict begin
            /cap exch def
            /y exch def
            newpath
            150 y moveto
            300 0 rlineto
            100 setlinewidth
            0.5 1 1 setrgbcolor
            cap setlinecap
            stroke
            newpath
            150 y moveto
            300 0 rlineto
            1 setlinewidth
            1 0 0 setrgbcolor
            0 setlinecap
            stroke
        end
    }def

    650 0 hline
    500 1 hline
    350 2 hline
    showpage

    join.ps

    % join
    /harpoon {
        2 dict begin
            /join exch def
            /y exch def
            newpath
            150 y moveto
            250 0 rlineto
            -150 120 rlineto
            80 setlinewidth
            0.5 1 1 setrgbcolor
            join setlinejoin
            stroke
            newpath
            150 y moveto
            250 0 rlineto
            -150 120 rlineto
            1 setlinewidth
            1 0 0 setrgbcolor
            0 setlinejoin
            stroke
        end
    }def

    600 0 harpoon
    400 1 harpoon
    200 2 harpoon
    showpage

    miter.ps 

    % join
    /harpoon {
        2 dict begin
            /join exch def
            /y exch def
            newpath
            150 y moveto
            250 0 rlineto
            -150 120 rlineto
            80 setlinewidth
            0.5 1 1 setrgbcolor
            join setlinejoin
            stroke
            newpath
            150 y moveto
            250 0 rlineto
            -150 120 rlineto
            1 setlinewidth
            1 0 0 setrgbcolor
            0 setlinejoin
            stroke
        end
    }def

    600 0 harpoon
    400 1 harpoon
    200 2 harpoon
    showpage

    dash.ps

    % dash
    /vline {
        newpath
        100 150 moveto
        100 750 lineto
        500 150 moveto
        500 750 lineto
        1 0 0 setrgbcolor
        stroke
    } def

    /hline {
        3 dict begin
            /offset exch def
            /array exch def
            /y exch def
            newpath
            100 y moveto
            400 0 rlineto
            0 0.4 0.8 setrgbcolor
            40 setlinewidth
            array offset setdash
            stroke
        end
    }def

    vline
    700 [] 0 hline
    600 [ 30 10 ] 0 hline
    500 [ 20 ] 0 hline
    400 [ 10 20 30 ] 0 hline
    300 [ 50 10 10 10 ] 0 hline
    200 [ 50 10 10 10 ] 20 hline
    showpage

    rowdash.ps

    % roudash
    newpath
    100 200 moveto
    400 0 rlineto
    -200 500 rlineto
    closepath
    60 setlinewidth
    0.4 0.8 0 setrgbcolor
    1 setlinecap
    1 setlinejoin
    [200 80] 0 setdash
    stroke
    showpage

     

  • PostScript実習マニュアル
  • PostScript - PDF,Web まとめ
  • PostScript file, ファイルIO

     

    access string

    % P.40 2.13 ファイル 2.13.2 ファイルのオープン
    % /in (hoge.txt) (access string) file def

    % access string
    % r
    % w
    % a
    % r+
    % w+
    % a+

     

    % P.43 2.13.8 標準入出力のファイルオブジェクト
    % 標準入力 %stdin
    % 標準出力 %stdout
    % 標準エラー %stderr
    % /in (%stdin) (r) file def

     

    IO関連オペレータ

    % file
    % closefile
    % read
    % readline
    % readstring
    % token
    % write
    % writestring
    % print
    % deletefile
    % renamefile

     

    読み込み

    /cat {
        3 dict begin
            /path exch def
            /in path (r) file def
            /s 256 string def
            {
                in s readline not {
                    pop exit
                } if
                =
            } loop
            in closefile
        end
    } def

    (c:/test.txt) cat
    % test
    % aaa
    % bbb
    % ccc

    % c:/test.txt
    % test
    % aaa
    % bbb
    % ccc

     

    コピー

    /copy {
        4 dict begin
            /path2 exch def
            /path1 exch def
            /in path1 (r) file def
    %         /out path2 (w) file def
            /out path2 (a+) file def
            {
                in read not {
                    exit
                } if
                out exch write
            } loop
            in closefile
            out closefile
        end
    } def

    (c:/test.txt) (c:/test1.txt) copy

     

    PostScript mmへの変換

    /mm {
        2.834646 mul
    } def

     

    PostScript fill, eofill

    fill-eofill-star

    % P.50 3.3.6 領域の内部性の判定

    /star {
        2 dict begin
            /y exch def
            /x exch def
            newpath
            x y moveto
            300 0 rlineto
            -250 -200 rlineto
            100 300 rlineto
            100 -300 rlineto
        end
    } def

    0 0.4 0 setrgbcolor
    150 650 star
    fill
    150 300 star
    eofill
    showpage

     

  • PostScript実習マニュアル
  • PostScript - PDF,Web まとめ
  • PostScript フィボナッチ数

    %!PS-Adobe-3.0
    % fibonacci

    /fib {
        1 dict begin
            /n exch def
            n 0 eq n 1 eq or {
                n
            } {
                n 2 sub fib
                n 1 sub fib
                add
            } ifelse
        end
    } def

    20 fib % 6765

     

    PostScript 階乗

    %!PS-Adobe-3.0 
    % factorial
    
    /fact { 
        1 dict begin 
            /n exch def 
            n 1 eq n 0 eq or { 
                1 
            } { 
                n 1 sub fact n mul 
            } ifelse 
        end 
    } def
    
    5 fact % 120

    PostScript GhostScript, some operators

     

    GS>(abcdefghijk) 3 4 getinterval ==
    (defg)

     

    GS>/s (abcdefghijk) def
    GS>s 3 (WXYZ) putinterval
    GS>s ==
    (abcWXYZhijk)

     

    GS>(437) cvi ==
    437

     

    GS>(3.14) cvr ==
    3.14

     

    GS>(kpf) cvn ==
    /kpf

     

    GS>437 3 string cvs ==
    (437)

     

    GS>(kpf) (9LISP) 123 5
    GS<4>pstack
    5
    123
    (9LISP)
    (kpf)

     

    GS<4>stack
    5
    123
    9LISP
    kpf
    GS<4>

     

    GS>(kpf) (9LISP) (hoge)
    GS<3>pop
    GS<2>stack
    9LISP
    kpf

     

    GS<2>count ==
    2
    GS<2>count

    GS<3>stack
    2
    9LISP
    kpf
    GS<3>pop
    GS<2>count ==
    2

     

    GS<2>clear
    GS>stack
    GS>

     

    GS>398 dup
    GS<2>pstack
    398
    398

     

    GS<2>(a) (b) (c) 2 index
    GS<6>pstack
    (a)
    (c)
    (b)
    (a)
    398
    398

     

    GS<6>(a) (b) (c) 3 copy
    GS<12>pstack
    (c)
    (b)
    (a)
    (c)
    (b)
    (a)
    (a)
    (c)
    (b)
    (a)
    398
    398

     

    GS<12>clear

     

    GS>(a) (b) (c) exch
    GS<3>pstack
    (b)
    (c)
    (a)

     

    GS<3>(9) (L) (I) (S) (P) 4 3 roll
    GS<8>pstack
    (L)
    (P)
    (S)
    (I)
    (9)
    (b)
    (c)
    (a)
    GS<8>

     

    GS>100 mark 1 2 3 4 5
    GS<7>pstack
    5
    4
    3
    2
    1
    -mark-
    100

     

    GS<7>counttomark
    GS<8>==
    5
    GS<7>counttomark ==
    5

     

    GS<7>cleartomark
    GS<1>pstack
    100
    GS<1>

    PostScript 配列を扱う手続き

     

    %!PS-Adobe-3.0
    % P.38 2.12.4 配列を扱う手続き

    /reverse {
        5 dict begin
            /ary exch def
            /n a1 length def
            /ret n array def
            0 1 n 1 sub {
                /i exch def
                /e ary i get def
                ret n i sub 1 sub e put
            } for
            ret
        end
    } def

    [1 2 3 4 5] reverse ==

    %!PS-Adobe-3.0
    % P.39 2.12.4 配列を扱う手続き
    % sum array elements

    /suma {
        2 dict begin
            /ary exch def
            /ret 0 def
            ary {
                /ret exch ret add def
            } forall
            ret
        end
    } def

    [1 2 3 4 5 6 7 8 9 10] suma == % 55

    %!PS-Adobe-3.0
    % P.40 2.12.4 配列を扱う手続き

    /amap {
        6 dict begin
            /f exch def
            /ary exch def
            /n ary length def
            /ret n array def
            0 1 n 1 sub {
                /i exch def
                /e ary i get def
                ret i e f put
            } for
            ret
        end
    } def

    [1 2 3 4 5] { 10 mul } amap ==
    % [10 20 30 40 50]
    [true false false true] { { 1 } { 0  } ifelse } amap ==
    % [1 0 0 1]

    PostScript hour minute to minute

     

    %!PS-Adobe-3.0
    % P.24 2.6.6 オペランドへの名前の束縛
    % hour時間minute分を分に変換
    /hmtom {
        2 dict begin
            /minute exch def
            /hour exch def
            hour 60 mul minute add
        end
    } def

    2 30 hmtom ==
    % 150

    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