Suche…


Ein Polygon zeichnen (beschreiben)

In diesem Beispiel wird versucht, das Verhalten der eingebauten Operator für die Pfadkonstruktion wie arc nachzuahmen.

Wenn es einen aktuellen Punkt gibt, zieht poly zuerst eine Linie zu (x, y) + (r, 0), ansonsten beginnt es mit dem Punkt.

Anstelle von gsave ... grestore (was den unerwünschten Effekt hat, dass alle Änderungen des aktuellen Pfads, die wir möchten, grestore ), speichert es eine Kopie der aktuellen Transformationsmatrix (CTM), die beim Start der Funktion vorhanden ist.

Dann ist es lineto zu jedem nachfolgenden Punkt, der durch Skalieren und Drehen der Matrix ist stets bei (0,1). Schließlich ruft es closepath und stellt die gespeicherte Matrix als CTM wieder her.

% x y n radius  poly  -
% construct a path of a closed n-polygon
/poly {
    matrix currentmatrix 5 1 roll  % matrix x y n radius
    4 2 roll translate             % matrix n radius
    dup scale                      % matrix n
    360 1 index div exch           % matrix 360/n n
    0 1 {lineto currentpoint moveto}stopped{moveto}if   % start or re-start subpath
    {                              % matrix 360/n
        dup rotate                 % matrix 360/n
        0 1 lineto                 % matrix 360/n
    } repeat                 % matrix 360/n
    pop                      % matrix
    closepath                % matrix
    setmatrix                %
} def

Durch einen Pfad iterieren

Dieses Snippet gibt den Inhalt des aktuellen Pfads in stdout aus. Es verwendet die Ghostscript-Prozedur =only die möglicherweise nicht für alle Interpreter verfügbar ist. Ein äquivalentes Verfahren für Adobe-Interpreter lautet =print .

pathforall ist ein Schleifenoperator, der 4 Prozedurgremien als Argumente verwendet, die für die spezifischen Arten von moveto , das Ergebnis von moveto , lineto , curveto , closepath und allen anderen closepath , die sich auf diese Elemente curveto , closepath werden.

{ exch =only ( ) print =only ( ) print /moveto =} 
{ exch =only ( ) print =only ( ) print /lineto =}
{ 6 -2 roll exch =only ( ) print =only ( ) print
  4 2 roll exch =only ( ) print =only ( ) print
  exch =only ( ) print =only ( ) print /curveto =}
{ /closepath = }
pathforall

Millimeterpapier

/in {72 mul} def
/delta {1 in 10 div} def
/X 612 def
/Y 792 def
0 delta Y {
    0 1 index X exch  % i 0 X i
    moveto exch       % 0 i
    lineto
    stroke
} for
0 delta X {
    0 1 index Y  % i 0 i Y
    moveto       % i 0
    lineto
    stroke
} for
showpage


Modified text is an extract of the original Stack Overflow Documentation
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow