demo/eps_demo.cc
author alpar
Fri, 08 Feb 2008 10:18:55 +0000
changeset 2568 046c055217f6
parent 2553 bfced05fa852
child 2569 12c2c5c4330b
permissions -rw-r--r--
Math constants + configure bugfix backported
from hg a315a588a20d and 761622e5ed4c
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 /// \ingroup demos
    20 /// \file
    21 /// \brief Demo of the EPS grawing class \ref lemon::EpsDrawer "EpsDrawer".
    22 ///
    23 /// This demo program shows examples how to use the class \ref
    24 /// lemon::EpsDrawer "EpsDrawer". It takes no input but simply creates
    25 /// a file <tt>eps_demo.eps</tt> demonstrating the capability of \ref
    26 /// lemon::EpsDrawer "EpsDrawer".
    27 ///
    28 /// \include eps_demo.cc
    29 
    30 #include <cmath>
    31 #include <lemon/eps.h>
    32 
    33 using namespace lemon;
    34 
    35 void kosar(EpsDrawer &ed)
    36 {
    37   double d,r;
    38   
    39   r = sqrt(2);
    40   
    41   ed.save();
    42   
    43   ed.translate(256,256).scale(256,256);
    44   ed.lineWidth(1/256);
    45   
    46   ed.collect();
    47   
    48   ed.moveTo(0,1);
    49   
    50   for(d=0;d<PI*2*5;d+=.1)
    51     {
    52       ed.lineTo(sin(d*3),cos(d*5));
    53     }
    54   
    55   ed.stroke();
    56   ed.restore();
    57   
    58 }
    59 
    60 void fonts(EpsDrawer &ed)
    61 {
    62   ed.save().centerMode(true);
    63   
    64   ed.font("Helvetica").fontSize(90);
    65   ed.moveTo(256,512/3*2+50) << "Helvetica";
    66   ed.font("Courier");
    67   ed.moveTo(256,512/3+50) << "Courier" ;
    68   ed.font("Times-Roman");
    69   ed.moveTo(256,50) << "Times-Roman";
    70   
    71   ed.centerMode(false).restore();
    72 }
    73 
    74 int main()
    75 {
    76 
    77   EpsDrawer ed("eps_demo.eps",512,512);
    78   ed.scale(1,1);
    79   
    80   ed.color(0,0,0).collect();
    81   ed.moveTo(0,0).lineTo(0,512).lineTo(512,512).lineTo(512,0).closePath().fill();
    82   
    83   ed.lineWidth(4);
    84   
    85   for(double r=0;r<=256;r+=2)
    86     {
    87       ed.color(r/256.0,0,1-r/256.0).circle(256,256,r);
    88     }
    89   
    90   
    91   ed.save();
    92   ed.color(0,0,0);
    93   ed.translate(256,256);
    94   
    95   for(int i=0;i<18;i++)
    96     {
    97       ed.rotate(20);
    98       
    99       for(double r=0;r<=256;r+=20)
   100 	ed.fontSize(r/10+1).rotate(2).moveTo(0,r) << r;
   101       ed.rotate(-26);
   102       
   103     }
   104   
   105   ed.restore();
   106   
   107   fonts(ed.color(.7,.7,.7));
   108   ed.color(0,1,0);
   109 
   110   ed.node(ed.CIRCLE,128,333,25);
   111   ed.node(ed.SQUARE,256,333,25);
   112   ed.node(ed.DIAMOND,128+256,333,25);
   113 
   114   kosar(ed);
   115 }