#include <fstream>

using namespace std;

#include "PostScript.h"

PostScript::PostScript(const char* name) : ofstream(name)
{
   *this << "%!PS\n";
   *this << "8.5 2 div 72 mul 11 2 div 72 mul translate\n";
   *this << "72 2.54 div dup scale\n";
   *this << "0.05 setlinewidth\n";
   *this << "1 setlinecap\n";
   X= 0;
   Y= 0;
   Zo= 60;
   Zp= 30;

}

PostScript::~PostScript(void)
{
   *this << "stroke\n";
   *this << "showpage\n";
}

void PostScript::moveto(double x, double y)
{
   *this << x << " " << y << " moveto\n";
   X= x;
   Y= y;
}

void PostScript::lineto(double x, double y)
{
   *this << x << " " << y << " lineto\n";
   X= x;
   Y= y;
}

void PostScript::moveto(double x, double y, double z)
{
    moveto( (Zo-Zp)*x/(Zo-z), (Zo-Zp)*y/(Zo-z) );
}

void PostScript::lineto(double x, double y, double z)
{
    lineto( (Zo-Zp)*x/(Zo-z), (Zo-Zp)*y/(Zo-z) );
}


void PostScript::setcolor(double r, double g, double b)
{
   *this << "stroke\n";
   *this << r << " " << g << " " << b << " setrgbcolor\n";
   moveto(X,Y);
}














