demo/eps_demo.cc
changeset 1971 9a59a6cacfd9
child 2008 0820d8168cbb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/demo/eps_demo.cc	Mon Feb 20 06:41:12 2006 +0000
     1.3 @@ -0,0 +1,110 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +/// \ingroup demos
    1.23 +/// \file
    1.24 +/// \brief Demo of the EPS grawing class \ref EpsDrawer()
    1.25 +///
    1.26 +/// This demo program shows examples how to use the class \ref
    1.27 +/// EpsDrawer(). It takes no input but simply creates a file
    1.28 +/// <tt>eps_demo.eps</tt> demonstrating the capability of \ref
    1.29 +/// EpsDrawer().
    1.30 +///
    1.31 +/// \include eps_demo.cc
    1.32 +
    1.33 +#include <cmath>
    1.34 +#include <lemon/eps.h>
    1.35 +
    1.36 +using namespace lemon;
    1.37 +
    1.38 +void kosar(EpsDrawer &ed)
    1.39 +{
    1.40 +  double d,r;
    1.41 +  
    1.42 +  r = sqrt(2);
    1.43 +  
    1.44 +  ed.save();
    1.45 +  
    1.46 +  ed.translate(256,256).scale(256,256);
    1.47 +  ed.lineWidth(1/256);
    1.48 +  
    1.49 +  ed.collect();
    1.50 +  
    1.51 +  ed.moveTo(0,1);
    1.52 +  
    1.53 +  for(d=0;d<M_PI*2*5;d+=.1)
    1.54 +    {
    1.55 +      ed.lineTo(sin(d*3),cos(d*5));
    1.56 +    }
    1.57 +  
    1.58 +  ed.stroke();
    1.59 +  ed.restore();
    1.60 +  
    1.61 +}
    1.62 +
    1.63 +void fonts(EpsDrawer &ed)
    1.64 +{
    1.65 +  ed.save().centerMode(true);
    1.66 +  
    1.67 +  ed.font("Helvetica").fontSize(90);
    1.68 +  ed.moveTo(256,512/3*2+50) << "Helvetica";
    1.69 +  ed.font("Courier");
    1.70 +  ed.moveTo(256,512/3+50) << "Courier" ;
    1.71 +  ed.font("Times-Roman");
    1.72 +  ed.moveTo(256,50) << "Times-Roman";
    1.73 +  
    1.74 +  ed.centerMode(false).restore();
    1.75 +}
    1.76 +
    1.77 +int main()
    1.78 +{
    1.79 +
    1.80 +  EpsDrawer ed("eps_demo.eps",512,512);
    1.81 +  ed.scale(1,1);
    1.82 +  
    1.83 +  ed.color(0,0,0).collect();
    1.84 +  ed.moveTo(0,0).lineTo(0,512).lineTo(512,512).lineTo(512,0).closePath().fill();
    1.85 +  
    1.86 +  ed.lineWidth(4);
    1.87 +  
    1.88 +  for(double r=0;r<=256;r+=2)
    1.89 +    {
    1.90 +      ed.color(r/256.0,0,1-r/256.0).circle(256,256,r);
    1.91 +    }
    1.92 +  
    1.93 +  
    1.94 +  ed.save();
    1.95 +  ed.color(0,0,0);
    1.96 +  ed.translate(256,256);
    1.97 +  
    1.98 +  for(int i=0;i<18;i++)
    1.99 +    {
   1.100 +      ed.rotate(20);
   1.101 +      
   1.102 +      for(double r=0;r<=256;r+=20)
   1.103 +	ed.fontSize(r/10+1).rotate(2).moveTo(0,r) << r;
   1.104 +      ed.rotate(-26);
   1.105 +      
   1.106 +    }
   1.107 +  
   1.108 +  ed.restore();
   1.109 +  
   1.110 +  fonts(ed.color(.7,.7,.7));
   1.111 +  ed.color(0,1,0);
   1.112 +  kosar(ed);
   1.113 +}