How to make pictures using postscript programs (part 7) ----------------------------------------------------------------------------- There is one further type of coordinate transformation, beyond translations and rotations, that we can use: scalings. The command scale has two parameters, scale factors for the first and second coordinate of the current coordinate system. Usually they are the same. If we wrtie 0.5 0.5 scale then in future everything will be drawn at half the size. So if our picture is too large, we give it a small scale factor, if the picture is too small, we can blow it up by saying, e.g., 2 2 scale which doubles its size. We can use different scale factors for the axes, so with 0.5 1 scale the x-axis will be compressed, but not the y-axis, so a circle becomes an ellipse. And giving a negative scale factor reverses the direction of the axis, so after -1 1 scale the positive direction of the x-axis is to the left instead of to the right. So -1 1 scale is a reflection on the vertical line x=0, and 1 -1 scale is a reflection on the horizontal line y=0. ---------------------Example Program 15-------------------------------------- %!PS-Adobe-2.0 %%BoundingBox: 0 0 400 410 200 200 translate 2 setlinewidth 0 0 0 setrgbcolor %Black newpath 0 0 190 0 360 arc stroke 0.8 1 scale 0.5 0.1 0 setrgbcolor %Dark red newpath 0 0 190 0 360 arc stroke 0.8 1 scale 0.7 0.1 0 setrgbcolor %Brighter Red newpath 0 0 190 0 360 arc stroke 0.8 1 scale 1.0 0.1 0 setrgbcolor %Full Red newpath 0 0 190 0 360 arc stroke 1 0.8 scale 1.0 0.4 0 setrgbcolor %Orange newpath 0 0 190 0 360 arc stroke 1 0.8 scale 1.0 0.8 0 setrgbcolor %Bright Orange newpath 0 0 190 0 360 arc stroke 1 0.8 scale 1.0 1.0 0 setrgbcolor %Yellow newpath 0 0 190 0 360 arc stroke showpage ------------------------------------------------------------------------------ Each scale command modifies the previous coordinate system, so the scale factors multiply. If you rotated your coordinate system, those scale factors apply to the rotated axes ------------------------------------------------------------------------------ You can store a coordinate system by gsave and recover it by grestore. These commands save and restore the entire graphics state, which contains - the coordinate system - the current path - the drawing colors, line thickness, line style, dash pattern etc - the clipping region ----------------------------------------------------------------------------- Since it stores your current path, this makes it possible to use the path again. Because the operations stroke and fill each destroy the current path, if you want to draw a region, and then draw a line along its boundary, you can first construct the path, e.g., newpath 100 100 moveto 200 100 lineto 150 186.6 lineto closepath and then save it, fill it, restore it, and draw (stroke) it. gsave 0 0.9 0.2 setrgbcolor fill grestore stroke %fills green, black boundary