How to make pictures using postscript programs (part 15) ----------------------------------------------------------------------------- We draw a black background, and on it squares in three-dimensional space, with three nested for loops. Squares get brighter to the front ---------------------------Example30------------------------------------------ %!PS-Adobe-2.0 EPSF %%BoundingBox: 0.0 0.0 400 400 %%Title: projected squares newpath 0 0 moveto 0 400 lineto 400 400 lineto 400 0 lineto closepath gsave 0 setgray fill grestore clip %Makes background black 200 200 translate %Puts viewpoint in center /proj {/z exch def /y exch def /x exch def x z div y z div} def %proj replaces numbers z y z by z/z y/z 200 -10 10 { /z1 exch def -20400 2000 20000 {/y1 exch def -20200 2000 20000 {/x1 exch def newpath x1 y1 z1 proj moveto x1 700 add y1 z1 proj lineto x1 700 add y1 700 add z1 proj lineto x1 y1 700 add z1 proj lineto closepath gsave 0 setgray 1.0 setlinewidth stroke grestore 0.9 z1 220 div sub setgray fill } for } for } for showpage ----------------------------------------------------------------------------- This is still not very satisfactory: who needs squares floating in space? But we can do a convincing three-dimensional ball with some fake lighting. ---------------------------Example31------------------------------------------ %!PS-Adobe-2.0 %%BoundingBox: 0.0 0.0 400 400 %%Title: projected balls newpath 0 0 moveto 0 400 lineto 400 400 lineto 400 0 lineto closepath gsave 0 setgray fill grestore clip %Makes background black 200 200 translate %Puts viewpoint in center /proj {/z exch def /y exch def /x exch def x z div y z div} def %proj replaces numbers z y z by z/z y/z /ball {/rad exch def /y1 exch def /x1 exch def 1 -0.05 0 {/t exch def newpath x1 1 t sub rad mul 0.5 mul add y1 1 t sub rad mul 0.3 mul add rad t mul 0 360 arc closepath t -0.7 mul 0.9 add setgray fill } for } def 170 -9 10 { /z2 exch def -8500 800 8000 {/y2 exch def -8200 800 8000 {/x2 exch def x2 y2 z2 proj %2d coordinates 180 z2 div %radius of projection ball } for } for } for showpage