import 'math' // for pi global class plotPostscript // A little plotter for postScript { file f; // Where to write output to init(file f, double width,height) // Initialize plotter - need output file and dimensions in // points (1 point = 1/72th of an inch.) { self.f = f; f.write(" %!PS-Adobe-3.1 EPSF-3.0 %%BoundingBox: 0 0 $width $height 1.0 setlinewidth "); } to line(double x1,y1,x2,y2) // Draw a line. { f.write(" $x1 $y1 moveto $x2 $y2 lineto stroke "); } to circle(double xCen,yCen,radius) // Draw a circle as a polygon with many sides { int sides = radius; if (sides < 16) sides = 16; int x = xCen+radius, y=yCen; f.write("$x $y moveto\n"); for (i in 1 til sides) { double angle = i * math.pi * 2 / sides; x = xCen + radius * cos(angle); y = yCen + radius * sin(angle); f.write("$x $y lineto\n"); } f.write("closepath\n"); f.write("stroke\n"); } }