PLplot 5.15.0
Loading...
Searching...
No Matches
cdmulti.c
Go to the documentation of this file.
1//
2// cdmulti is a program to make a cgm file with multiple pictures in it.
3//
4//
5// cdmulti.c: test program for the cgmdraw module.
6//
7// Written by G. Edward Johnson <mailto:lorax@nist.gov>
8// Date: June 26, 1996
9// Copyright: cd software produced by NIST, an agency of the
10// U.S. government, is by statute not subject to copyright
11// in the United States. Recipients of this software assume all
12// responsibilities associated with its operation, modification
13// and maintenance.
14//
15//
16
17
18#include <stdio.h>
19#include <math.h>
20#include <string.h>
21#include <stdlib.h>
22#include "defines.h"
23#include "cd.h"
24
25
26int main()
27{
28 // you must create a pointer to the image(s) that you will be using
29 // not suprisingly, it is of type cdImagePtr
30 cdImagePtr im;
31
32 // this is a pointer to the output file you will be using
33 FILE *outf;
34
35 // these will be index's into the color palette containing
36 // the corresponding colors
37 int black, white, blue;
38
39
40 // Create an image 200 pixels wide by 250 pixels high
41 im = cdImageCreate( 200, 250 );
42
43 // allocate some colors (isn't this fun?)
44 // the first color allocated is the background color
45 white = cdImageColorAllocate( im, 255, 255, 255 );
46 black = cdImageColorAllocate( im, 0, 0, 0 );
47 blue = cdImageColorAllocate( im, 0, 0, 255 );
48
49 // set the text attributes
50 // font, colorindex, and size respectivily
51
52 // font is the style the text is written in. 1 is for Times,
53 // 5 is for Helvetica.
54 // we will have black text for this one
55 // Size is a tough one, but larger numbers give larger text.
56 // 25 is a not too large size
57 if ( !( cdSetTextAttrib( im, 5, black, 25 ) ) )
58 return 1;
59
60
61 // Now that we have set some attributes, lets do some drawing
62
63 // lets put some text in the picture.
64 // (20,100) is the point at the lower left corner of the text
65 if ( !( cdText( im, 20, 100, "Hello World" ) ) )
66 return 1;
67
68
69 // Here's something special, put a second picture in the file
70 // we put in a second picture, and reset all defaults. This means
71 // we have to re-allocate the colors as well
72 if ( !( cdCgmNewPic( im, 0 ) ) )
73 return 1;
74
75 // allocate some colors (Again!)
76 // the first color allocated is the background color
77 white = cdImageColorAllocate( im, 255, 255, 255 );
78 black = cdImageColorAllocate( im, 0, 0, 0 );
79 blue = cdImageColorAllocate( im, 0, 0, 255 );
80 // set text attributes
81 if ( !( cdSetTextAttrib( im, 5, black, 25 ) ) )
82 return 1;
83 if ( !( cdText( im, 20, 100, "Goodbye World" ) ) )
84 return 1;
85
86
87 // now write the file out.
88 outf = fopen( "cdmulti.cgm", "wb" );
89 if ( !outf )
90 return 1;
91 cdImageCgm( im, outf );
92 fclose( outf );
93 outf = 0;
94
95 // Remember to destroy the image when you are done
96 cdImageDestroy( im );
97 im = 0;
98
99 printf( "I just created a multi picture CGM!!!\n" );
100
101 return 0;
102}
int cdImageCgm(cdImagePtr im, FILE *out)
Definition: cd.c:560
int cdCgmNewPic(cdImagePtr im, int sticky)
Definition: cd.c:542
int cdSetTextAttrib(cdImagePtr im, int font, int color, int height)
Definition: cd.c:1720
int cdImageColorAllocate(cdImagePtr im, int r, int g, int b)
Definition: cd.c:1966
int cdText(cdImagePtr im, int x, int y, const char *ts)
Definition: cd.c:2945
int cdImageDestroy(cdImagePtr im)
Definition: cd.c:1766
cdImagePtr cdImageCreate(int sx, int sy)
Definition: cd.c:31
int main()
Definition: cdmulti.c:26