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

cdmulti.c

Go to the documentation of this file.
00001 //
00002 // cdmulti is a program to make a cgm file with multiple pictures in it.
00003 //
00004 //
00005 // cdmulti.c: test program for the cgmdraw module.
00006 //
00007 //      Written by G. Edward Johnson <mailto:lorax@nist.gov>
00008 //      Date: June 26, 1996
00009 //      Copyright: cd software produced by NIST, an agency of the
00010 //      U.S. government, is by statute not subject to copyright
00011 //      in the United States. Recipients of this software assume all
00012 //      responsibilities associated with its operation, modification
00013 //      and maintenance.
00014 //
00015 //
00016 
00017 
00018 #include <stdio.h>
00019 #include <math.h>
00020 #include <string.h>
00021 #include <stdlib.h>
00022 #include "defines.h"
00023 #include "cd.h"
00024 
00025 
00026 int main()
00027 {
00028     // you must create a pointer to the image(s) that you will be using
00029     // not suprisingly, it is of type cdImagePtr
00030     cdImagePtr im;
00031 
00032     // this is a pointer to the output file you will be using
00033     FILE *outf;
00034 
00035     // these will be index's into the color palette containing
00036     // the corresponding colors
00037     int black, white, blue;
00038 
00039 
00040     // Create an image 200 pixels wide by 250 pixels high
00041     im = cdImageCreate( 200, 250 );
00042 
00043     // allocate some colors (isn't this fun?)
00044     // the first color allocated is the background color
00045     white = cdImageColorAllocate( im, 255, 255, 255 );
00046     black = cdImageColorAllocate( im, 0, 0, 0 );
00047     blue  = cdImageColorAllocate( im, 0, 0, 255 );
00048 
00049     // set the text attributes
00050     // font, colorindex, and size respectivily
00051 
00052     // font is the style the text is written in. 1 is for Times,
00053     // 5 is for Helvetica.
00054     // we will have black text for this one
00055     // Size is a tough one,  but larger numbers give larger text.
00056     // 25 is a not too large size
00057     if ( !( cdSetTextAttrib( im, 5, black, 25 ) ) )
00058         return 1;
00059 
00060 
00061     // Now that we have set some attributes, lets do some drawing
00062 
00063     // lets put some text in the picture.
00064     // (20,100) is the point at the lower left corner of the text
00065     if ( !( cdText( im, 20, 100, "Hello World" ) ) )
00066         return 1;
00067 
00068 
00069     // Here's something special, put a second picture in the file
00070     // we put in a second picture, and reset all defaults.  This means
00071     // we have to re-allocate the colors as well
00072     if ( !( cdCgmNewPic( im, 0 ) ) )
00073         return 1;
00074 
00075     // allocate some colors (Again!)
00076     // the first color allocated is the background color
00077     white = cdImageColorAllocate( im, 255, 255, 255 );
00078     black = cdImageColorAllocate( im, 0, 0, 0 );
00079     blue  = cdImageColorAllocate( im, 0, 0, 255 );
00080     // set text attributes
00081     if ( !( cdSetTextAttrib( im, 5, black, 25 ) ) )
00082         return 1;
00083     if ( !( cdText( im, 20, 100, "Goodbye World" ) ) )
00084         return 1;
00085 
00086 
00087     // now write the file out.
00088     outf = fopen( "cdmulti.cgm", "wb" );
00089     if ( !outf )
00090         return 1;
00091     cdImageCgm( im, outf );
00092     fclose( outf );
00093     outf = 0;
00094 
00095     // Remember to destroy the image when you are done
00096     cdImageDestroy( im );
00097     im = 0;
00098 
00099     printf( "I just created a multi picture CGM!!!\n" );
00100 
00101     return 0;
00102 }

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