• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

cdsimple.c

Go to the documentation of this file.
00001 //
00002 // cdsimple is a very simple program that uses the cd library.
00003 // it will walk you through the basics.
00004 //
00005 //
00006 // cdsimple.c: test program for the cgmdraw module.
00007 //
00008 //      Written by G. Edward Johnson <mailto:lorax@nist.gov>
00009 //      Date: April 1996
00010 //      Copyright: cd software produced by NIST, an agency of the
00011 //      U.S. government, is by statute not subject to copyright
00012 //      in the United States. Recipients of this software assume all
00013 //      responsibilities associated with its operation, modification
00014 //      and maintenance.
00015 //
00016 //
00017 
00018 
00019 #ifndef NOMALLOCH
00020 #include <malloc.h>
00021 #endif
00022 #include <stdio.h>
00023 #include <math.h>
00024 #include <string.h>
00025 #include <stdlib.h>
00026 #include "defines.h"
00027 #include "cd.h"
00028 
00029 
00030 int main()
00031 {
00032     // you must create a pointer to the image(s) that you will be using
00033     // not suprisingly, it is of type cdImagePtr
00034     cdImagePtr im;
00035 
00036     // this is a pointer to the output file you will be using
00037     FILE *outf;
00038 
00039     // these will be index's into the color palette containing
00040     // the corresponding colors
00041     int black, white, blue;
00042 
00043 
00044     // Create an image 400 pixels wide by 500 pixels high
00045     im = cdImageCreate( 400, 500 );
00046 
00047     // allocate some colors (isn't this fun?)
00048     // the first color allocated is the background color
00049     white = cdImageColorAllocate( im, 255, 255, 255 );
00050     black = cdImageColorAllocate( im, 0, 0, 0 );
00051     blue  = cdImageColorAllocate( im, 0, 0, 255 );
00052 
00053     // Set the fill attributes
00054     // fill, colorindex, and hatch respectivily
00055     // see the cd documentation for a complete description
00056 
00057     // fill is the color that will be on the inside of filled objects
00058     // such as rectangles and polygons.
00059     // It can be 1 for solid color, 2 for hatch pattern, 4 for empty
00060     // let's use blue for the fill color
00061     // we are going to set it to solid, so the hatch pattern doesn't
00062     // matter.  we will signify no change by putting in -1
00063     if ( !( cdSetShapeFillAttrib( im, 1, blue, -1 ) ) )
00064         return 1;
00065 
00066     // notice that we also checked to make sure the command actually
00067     // worked.
00068 
00069     // we don't want the edges of our shapes to be a different color
00070     // so make them invisible.  0 means invisible, 1 means visible.
00071     if ( !( cdSetEdgeVis( im, 0 ) ) )
00072         return 1;
00073 
00074 
00075     // set the text attributes
00076     // font, colorindex, and size respectivily
00077 
00078     // font is the style the text is written in. 1 is for Times,
00079     // 5 is for Helvetica.
00080     // we will have black text for this one
00081     // Size is a tough one,  but larger numbers give larger text.
00082     // 25 is a not too large size
00083     if ( !( cdSetTextAttrib( im, 5, black, 25 ) ) )
00084         return 1;
00085 
00086 
00087 
00088     // Now that we have set some attributes, lets do some drawing
00089 
00090     // Draw a rectangle (10,450) is upper left, (350,350) is lower right
00091     if ( !( cdRectangle( im, 10, 450, 350, 350 ) ) )
00092         return 1;
00093 
00094     // lets put some text in the picture too.
00095     // (100,100) is the point at the lower left corner of the text
00096     if ( !( cdText( im, 100, 100, "Hello World" ) ) )
00097         return 1;
00098 
00099 
00100 
00101     // now write the file out, lets call it cdsimple.cgm
00102     outf = fopen( "cdsimple.cgm", "wb" );
00103     if ( !outf )
00104         return 1;
00105     cdImageCgm( im, outf );
00106     fclose( outf );
00107     outf = 0;
00108 
00109     // Remember to destroy the image when you are done
00110     cdImageDestroy( im );
00111     im = 0;
00112 
00113     printf( "I just created a simple CGM!!!\n" );
00114 
00115     return 0;
00116 }

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1