Drawing with postscript II, 13th of May 2013.

a circle squashed in a pentagon

After >> the first part of the introduction to postscript, here comes the second one. Here I intend to explain how one can "paint" in postscript, i.e., how, in addition to lines which I explained in >> the previous post, one gets colored areas. Let us first make the opening of the PS file:

%!PS-Adobe-2.0
gsave
1 setlinejoin
1 setlinecap
newpath


A colored area in postscript can be a polygon with colored interior. First we set the color of the interior (in this case a shade of gray):

0.75 0.75 0.75 setrgbcolor

And then we move (moveto) the "pointer" to one of the vertices of the polygon:

274.5 312.1 moveto

Using lineto statements we jump on the vertices of the polygon that we will fill, all until the last point / vertex, neighboring the first point which we set up using the moveto statement:

275.2 312.6 lineto
276.2 312.0 lineto
276.4 310.9 lineto
275.7 310.5 lineto
274.7 310.9 lineto


In the end, with the fill statement we fill up the polygon with the color we specified (0.75, 0.75, 0.75):

fill

The statement fill colors, but also closes the polygon, joining the last point of the polygon (274.7, 310.9) with the first one (274.5, 312.1), as is illustrated on the image which opened this post.

This procedure is repeated as many times as there are polygons which we want to paint / draw. In the end, the file is closed:

grestore
showpage


The postscript file used to make the image which opened this post can be >> downloaded HERE.

Besides polygons, in postscript one can very easily draw circles, i.e. circular pieces using the arc statement. I made the image below using exclusively circles which were positioned so to get the three-dimensional representation of a virus. The circles, representing amino-acids, were colored differently, depending on their (three-dimensional) distance from the (three-dimensional) center of the shape / virus.

3D virus made in postscript

We first specify the color of the circle that we will draw:

0.999 0.649 0.0513 setrgbcolor

And then we draw it using:

309.37 366.75 2.39 0 360 arc fill

The first two numbers (309.37, 366.75) specify the center of the circle, the third one (2.39) specifies its radius, and the fourth and fifth one (0, 360) specify the starting and the finishing angle of the arc - for whole circles these angles are always 0 and 360, but interesting shapes (half-circles, quarter-circles and similar) can also be obtained by decreasing the final angle. One can also easily draw nice pie-charts using only the arc statements. Finally, the statement arc actually makes the arc, and the statement fill closes it and fills it up with the specified color.

When the shapes in postscript overlap, as is the case with the virus shown, one should remember that postscript draws over what was already drawn, i.e. the shapes which are in the PS file specified later, are drawn over those specified earlier.

Although postscript was not conceived for 3D visualization, the example above, and the examples from >> the previous post show that it can be used to this end and that the results obtained can be good. To use the postscript in such a way, it is crucial to have a mathematical understanding of perspective which will be the subject of a post soon to come.

The image below shows the same virus visualized using POV-Ray - one can observe how the shadows on the object contribute to the comprehension of its 3D nature. We can clearly note the periodicity of the protein structure (hexamers) of the virus capsid and we see that it is a T=21 virus (see >> T-number poster for details).

3D virus made with POV-Ray

UPDATE: (21st of May, 2013) And >> HERE is the third part of the intro to postscript.

<< We humans >> Drawing with postscript III

Last updated on 21st of May, 2013.