수색…


다각형 그리기 (설명)

이 예제에서는 arc 와 같은 기본 제공 경로 생성 연산자의 동작을 모방하려고 시도합니다.

현재 점이 있으면 poly 는 (x, y) + (r, 0)에 선을 그립니다. 그렇지 않으면 그 점으로 이동하여 시작합니다.

gsave ... grestore (우리가 원하는 현재 경로의 변경을 버리는 바람직하지 못한 효과가 grestore 대신에, 함수가 시작될 때 현재 변형 행렬 (CTM)의 복사본을 저장합니다.

그리고 행렬의 크기를 조절하고 회전 시키면 항상 (0,1)에있는 각 후행 점에 대해 lineto 를 수행합니다. 마지막으로 closepath 호출 한 다음 저장된 행렬을 CTM으로 복원합니다.

% 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

경로 반복

이 스 니펫은 현재 경로의 내용을 stdout으로 덤프합니다. 그것은 고스트 절차를 사용 =only 모든 통역에서 사용하지 못할 수있다. Adobe 인터프리터에서 이와 동일한 절차를 =print 라고합니다.

pathforall 은 경로 요소의 특정 유형, moveto , lineto , curveto , closepath 및 이러한 요소를 curveto 하는 기타 모든 경로 생성 연산자의 결과에 대해 호출되는 인수로 4 개의 프로 시저 본문을 사용하는 루핑 연산자입니다.

{ 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

모눈 종이

/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
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow