/MatrixWithValueDict 2 dict def 
 
/MatrixWithValue 
{ 
  MatrixWithValueDict begin 
    /value exch def /matrix 16 array def 
    0 1 15 {matrix exch value put} for 
    matrix 
  end 
} def 
 
/IdentityMatrixDict 1 dict def 
 
/IdentityMatrix 
{ 
  IdentityMatrixDict begin 
    /matrix 0 MatrixWithValue def 
    0 5 15 {matrix exch 1 put} for 
    matrix 
  end 
} def 
 
/IndexDict 2 dict def 
 
/Index 
{ 
  IndexDict begin 
    /j exch def 
    /i exch def 
    i 4 mul j add 
  end 
} def 
 
/MatMultiplyDict 9 dict def 
 
/MatMultiply 
{ 
  MatMultiplyDict begin 
    /B exch def 
    /A exch def 
    /sum 0 def /matrix 16 array def 
 
      0 1 3 
      {/i exch def 
        0 1 3 
        {/j exch def 
          /sum 0 def 
          0 1 3 
          {/k exch def 
           /sum A i k Index get B k j Index get mul sum add def 
          } for 
          matrix i j Index sum put 
       } for 
      } for 
      matrix 
  end 
} def 
 
/CrossProductDict 3 dict def 
 
/CrossProduct 
{ 
  CrossProductDict begin 
    /b exch def 
    /a exch def 
    /c 3 array def 
    c 0 a 1 get b 2 get mul a 2 get b 1 get mul sub put 
    c 1 a 2 get b 0 get mul a 0 get b 2 get mul sub put 
    c 2 a 0 get b 1 get mul a 1 get b 0 get mul sub put 
    c 
  end 
} def 
 
/NormDict 3 dict def 
 
/Norm 
{ 
  NormDict begin 
    /a exch def 
    /b 3 array def 
    a b copy pop 
    /n 0 b {dup mul add} forall def 
    /n n sqrt def 
    b {n div} forall b astore 
  end 
} def 
 
/DotProductDict 5 dict def 
 
/DotProduct 
{ 
  DotProductDict begin 
    /b exch def /a exch def 
    /n 0 def 
    0 1 2 
    {/i exch def 
     /n a i get b i get mul n add def 
    } for 
    n 
  end 
} def 
 
/VectorSumDict 4 dict def 
 
/VectorSum 
{ 
  VectorSumDict begin 
    /b exch def /a exch def 
    /c 0 0 0 3 array astore def 
    0 1 2 
    {/i exch def 
     c i a i get b i get add put 
    } for 
    c 
  end 
} def 
 
/VectorDiffDict 4 dict def 
 
/VectorDiff 
{ 
  VectorDiffDict begin 
    /b exch def /a exch def 
    /c 0 0 0 3 array astore def 
    0 1 2 
    {/i exch def 
     c i a i get b i get sub put 
    } for 
    c 
  end 
} def 
 
/PointByMatrixDict 6 dict def 
 
/PointByMatrix 
{ 
  PointByMatrixDict begin 
    /m exch def /p exch def 
    /hp 4 array def 
    /q 3 array def 
    0 1 3 
    { 
      /j exch def 
      hp j m 3 j Index get put 
      0 1 2 
      { 
        /i exch def 
        hp j hp j get p i get m i j Index get mul add put 
      } for 
    } for 
    hp aload pop pop q astore 
    q {hp 3 get div} forall q astore 
  end 
} def 
 
/PointByMatrixToCoordsDict 6 dict def 
 
/PointByMatrixToCoords 
{ 
  PointByMatrixToCoordsDict begin 
    /m exch def /p exch def 
    /hp 4 array def 
    0 1 3 
    { 
      /j exch def 
      hp j m 3 j Index get put 
      0 1 2 
      { 
        /i exch def 
        hp j hp j get p i get m i j Index get mul add put 
      } for 
    } for 
    /w hp 3 get def 
    hp 0 get w div hp 1 get w div 
  end 
} def 
 
/ViewRepresentation 2 dict def 
ViewRepresentation begin 
  /ViewMatrix IdentityMatrix def 
  /displaymatrix matrix def 
end 
 
/ViewSpecification 8 dict def 
ViewSpecification begin 
  /vpn 0 0 -1 3 array astore def 
  /vuv 0 1  0 3 array astore def 
  /vrp 0 0  0 3 array astore def 
  /cop 0 0  0 3 array astore def 
  /vd 0 def 
  /dmin -1 def 
  /dmax 1 def 
  /vwin 0 1 0 1 4 array astore def 
end 
 
/SetViewportDict 10 dict def 
 
/SetViewport 
{ 
  SetViewportDict begin 
    /ymax exch def /ymin exch def 
    /xmax exch def /xmin exch def 
    /dx xmax xmin sub 2 div def 
    /dy ymax ymin sub 2 div def 
 
    /f0 xmin dx add def 
    /f1 dx def 
    /f2 ymin dy add def 
    /f3 dy def 
 
    ViewRepresentation begin 
      /displaymatrix f1 0 0 f3 f0 f2 displaymatrix astore 
    end 
  end 
} def 
 
/SetViewDict 16 dict def 
 
/SetView 
{ 
  ViewSpecification begin 
    ViewRepresentation begin 
      SetViewDict begin 
        /n vpn Norm def 
        /u n vuv CrossProduct Norm def 
        /v u n CrossProduct def 
          /VM IdentityMatrix def 
          0 1 2 
          { /i exch def 
            VM i 0 Index u i get put 
 
            VM i 1 Index v i get put 
 
            VM i 2 Index n i get put 
 
            VM 3 0 Index 
              VM 3 0 Index get vrp i get u i get mul sub 
            put 
 
            VM 3 1 Index 
              VM 3 1 Index get vrp i get v i get mul sub 
            put 
 
            VM 3 2 Index 
              VM 3 2 Index get vrp i get n i get mul sub put
          } for 
          0 1 2 
          { /i exch def 
            VM 3 i Index 
              VM 3 i Index get cop i get vrp i get add sub 
            put 
          } for
 
          /VD vd cop 2 get sub def 
 
          /DMIN dmin cop 2 get sub def 
 
          /DMAX dmax cop 2 get sub def 
 
          /dx vwin 1 get vwin 0 get sub def 
          /dy vwin 3 get vwin 2 get sub def 
          /px vwin 1 get vwin 0 get add def 
          /py vwin 3 get vwin 2 get add def 
          /dD DMAX DMIN sub def 
 
          /P 0 MatrixWithValue def 
          P 0 0 Index 2 VD dx div mul put 
 
          P 1 1 Index 2 VD dy div mul put 
 
          P 2 0 Index px dx div neg put 
 
          P 2 1 Index py dy div neg put 
 
          P 2 2 Index DMAX dD div put 
 
          P 2 3 Index 1 put 
 
          P 3 2 Index DMIN DMAX dD div mul neg put 
 
          /ViewMatrix VM P MatMultiply store 
 
        end 
      end 
    end 
} def 
 
/SetVPNDict 3 dict def 
 
/SetVPN 
{ 
  ViewSpecification begin 
    SetVPNDict begin 
      /z exch def /y exch def /x exch def 
      /vpn x y z vpn astore store 
    end 
  end 
} def 
 
/SetVUVDict 3 dict def 
 
/SetVUV 
{ 
  ViewSpecification begin 
    SetVUVDict begin 
      /z exch def /y exch def /x exch def 
      /vuv x y z vuv astore store 
    end 
  end 
} def 
 
/SetVRPDict 3 dict def 
 
/SetVRP 
{ 
  ViewSpecification begin 
    SetVRPDict begin 
      /z exch def /y exch def /x exch def 
      /vrp x y z vrp astore store 
    end 
  end 
} def 
 
/SetCOPDict 3 dict def 
 
/SetCOP 
{ 
  ViewSpecification begin 
    SetCOPDict begin 
      /z exch def /y exch def /x exch def 
      /cop x y z cop astore store 
    end 
  end 
} def 
 
/SetViewDistance 
{ 
  ViewSpecification begin 
    /dmax exch store 
    /dmin exch store 
    /vd exch store 
  end 
} def 
 
/SetViewWindowDict 4 dict def 
 
/SetViewWindow 
{ 
  ViewSpecification begin 
    SetViewWindowDict begin 
      /ymax exch def /ymin exch def 
      /xmax exch def /xmin exch def 
      /vwin xmin xmax ymin ymax vwin astore store 
    end 
  end 
} def 
 
/path3DDict 3 dict def 
 
/path3D 
{ 
  ViewRepresentation begin 
    path3DDict begin 
      /parray exch def 
      /qarray parray length 1 sub array def 
 
      parray 0 get ViewMatrix PointByMatrixToCoords 
      displaymatrix transform 
      moveto 
 
      /qarray parray aload length -1 roll pop qarray astore def 
      qarray {ViewMatrix PointByMatrixToCoords 
              displaymatrix transform 
              lineto 
             } forall 
    end 
  end 
} def 
 
/sumPointsDivDict 5 dict def 
 
/sumPointsDiv 
{ 
  sumPointsDivDict begin 
    /d exch def /q exch def /p exch def 
    /s 3 array def 
    0 1 2 
    { 
      /i exch def 
      s i 
        p i get q i get add d div 
      put 
    } for 
    s 
  end 
} def 
 
/sumPointsDict 4 dict def 
 
/sumPoints 
{ 
  sumPointsDict begin 
    /q exch def /p exch def 
    /s 3 array def 
    0 1 2 
    { 
      /i exch def 
      s i 
        p i get q i get add 
      put 
    } for 
    s 
  end 
} def 
 
/pointDivDict 4 dict def 
 
/pointDiv 
{ 
  pointDivDict begin 
    /d exch def /p exch def 
    /q 3 array def 
    0 1 2 
    { 
      /i exch def 
      q i 
        p i get d div 
      put 
    } for 
    q 
  end 
} def 
 
/splitDict 4 dict def 
 
/split 
{ 
  splitDict begin 
    /p exch def 
    /q 4 array def /r 4 array def 
 
    q 0 
      p 0 get 
    put 
 
    q 1 
      p 0 get p 1 get 2 sumPointsDiv 
    put 
 
    /t p 1 get p 2 get 4 sumPointsDiv 3 array copy def 
 
    q 2 
      q 1 get 2 pointDiv 
      t 
      sumPoints 
    put 
 
    r 3 p 3 get put 
 
    r 2 
      p 2 get p 3 get 2 sumPointsDiv 
    put 
 
    r 1 
      t 
      r 2 get 2 pointDiv 
      sumPoints 
    put 
 
    q 3 
      q 2 get r 1 get 2 sumPointsDiv 
    put 
 
    r 0 q 3 get put 
 
    q r 
  end 
} def 
 
/splitControlGraphDict 9 dict def 
/decomposeDict 5 dict def 
 
/splitControlGraph 
{ 
  splitControlGraphDict begin 
    /p exch def 
    /q 4 array def /r 4 array def /s 4 array def /t 4 array def 
    /u 4 array def /v 4 array def 
 
    0 1 3 
    { 
      /i exch def 
      p i get split 
      v exch i exch put u exch i exch put 
    } for 
 
    /decompose 
    { 
      decomposeDict begin 
        /r exch def /q exch def /u exch def 
        0 1 3 
        { 
          /j exch def 
          0 1 3 
          { 
            /i exch def 
            u i get j get 
          } for 
          4 array astore split 
          r exch j exch put q exch j exch put 
        } for 
      end 
    } def 
 
    u q r decompose 
    v s t decompose 
 
    q r s t 
  end 
} def 
 
/pathControlGraphDict 3 dict def 
 
/pathControlGraph 
{ 
  pathControlGraphDict begin 
    /p exch def 
    0 1 3 
    { 
      /j exch def 
      p j get path3D 
      0 1 3 
      { 
        /i exch def 
        p i get j get 
      } for 
      4 array astore path3D 
    } for 
  end 
} def 
 
/simpleBezier 
{ 
  4 dict begin 
    /n exch def /p exch def 
    0 n eq 
 
      {p pathControlGraph } 
 
      { 
        /nm1 n 1 sub def 
        /g p splitControlGraph 4 array astore def 
        g {nm1 simpleBezier} forall 
      } 
    ifelse 
  end 
} def 
 
/Step 
{ 
  /G 
  [ 
    [  [0.0 1.0 1.0] [0.3 1.0 1.0] [0.7 1.0 1.0] [1.0 1.0 1.0] ] 
    [  [0.0 1.0 0.5] [0.3 1.0 0.5] [0.7 1.0 0.5] [1.0 1.0 0.5] ] 
    [  [0.0 0.0 0.5] [0.3 0.0 0.5] [0.7 0.0 0.5] [1.0 0.0 0.5] ] 
    [  [0.0 0.0 0.0] [0.3 0.0 0.0] [0.7 0.0 0.0] [1.0 0.0 0.0] ] 
  ] 
  def 
  0.5 0.5 1.0 SetVRP 
  1.0 0.5 0.0 SetVPN 
  0.0 0.0 1.0 SetVUV 
  -4 1 -4 1 SetViewWindow 
  0 -4 4 SetViewDistance 
  0 0 -3 SetCOP 
  SetView 
} def 
 
/axes 
{ 
  /Xaxis {[[0 0 0] [1.5 0 0]] path3D} def 
  /Yaxis {[[0 0 0] [0 1.5 0]] path3D} def 
  /Zaxis {[[0 0 0] [0 0 1.5]] path3D} def 
  gsave 
    1 setlinewidth 
    Xaxis  
    Yaxis  
    Zaxis  
  grestore 
} def 
 
/main 
{ 
  -200 72 translate 
  2 2 scale
  0 500 0 500 SetViewport 
  Step 
  G 2 simpleBezier 
  G pathControlGraph
  axes 
  clear
} def 
 
main 
