PLplot 5.15.0
cdsimple.c
Go to the documentation of this file.
1//
2// cdsimple is a very simple program that uses the cd library.
3// it will walk you through the basics.
4//
5//
6// cdsimple.c: test program for the cgmdraw module.
7//
8// Written by G. Edward Johnson <mailto:lorax@nist.gov>
9// Date: April 1996
10// Copyright: cd software produced by NIST, an agency of the
11// U.S. government, is by statute not subject to copyright
12// in the United States. Recipients of this software assume all
13// responsibilities associated with its operation, modification
14// and maintenance.
15//
16//
17
18
19#ifndef NOMALLOCH
20#include <malloc.h>
21#endif
22#include <stdio.h>
23#include <math.h>
24#include <string.h>
25#include <stdlib.h>
26#include "defines.h"
27#include "cd.h"
28
29
30int main()
31{
32 // you must create a pointer to the image(s) that you will be using
33 // not suprisingly, it is of type cdImagePtr
34 cdImagePtr im;
35
36 // this is a pointer to the output file you will be using
37 FILE *outf;
38
39 // these will be index's into the color palette containing
40 // the corresponding colors
41 int black, white, blue;
42
43
44 // Create an image 400 pixels wide by 500 pixels high
45 im = cdImageCreate( 400, 500 );
46
47 // allocate some colors (isn't this fun?)
48 // the first color allocated is the background color
49 white = cdImageColorAllocate( im, 255, 255, 255 );
50 black = cdImageColorAllocate( im, 0, 0, 0 );
51 blue = cdImageColorAllocate( im, 0, 0, 255 );
52
53 // Set the fill attributes
54 // fill, colorindex, and hatch respectivily
55 // see the cd documentation for a complete description
56
57 // fill is the color that will be on the inside of filled objects
58 // such as rectangles and polygons.
59 // It can be 1 for solid color, 2 for hatch pattern, 4 for empty
60 // let's use blue for the fill color
61 // we are going to set it to solid, so the hatch pattern doesn't
62 // matter. we will signify no change by putting in -1
63 if ( !( cdSetShapeFillAttrib( im, 1, blue, -1 ) ) )
64 return 1;
65
66 // notice that we also checked to make sure the command actually
67 // worked.
68
69 // we don't want the edges of our shapes to be a different color
70 // so make them invisible. 0 means invisible, 1 means visible.
71 if ( !( cdSetEdgeVis( im, 0 ) ) )
72 return 1;
73
74
75 // set the text attributes
76 // font, colorindex, and size respectivily
77
78 // font is the style the text is written in. 1 is for Times,
79 // 5 is for Helvetica.
80 // we will have black text for this one
81 // Size is a tough one, but larger numbers give larger text.
82 // 25 is a not too large size
83 if ( !( cdSetTextAttrib( im, 5, black, 25 ) ) )
84 return 1;
85
86
87
88 // Now that we have set some attributes, lets do some drawing
89
90 // Draw a rectangle (10,450) is upper left, (350,350) is lower right
91 if ( !( cdRectangle( im, 10, 450, 350, 350 ) ) )
92 return 1;
93
94 // lets put some text in the picture too.
95 // (100,100) is the point at the lower left corner of the text
96 if ( !( cdText( im, 100, 100, "Hello World" ) ) )
97 return 1;
98
99
100
101 // now write the file out, lets call it cdsimple.cgm
102 outf = fopen( "cdsimple.cgm", "wb" );
103 if ( !outf )
104 return 1;
105 cdImageCgm( im, outf );
106 fclose( outf );
107 outf = 0;
108
109 // Remember to destroy the image when you are done
110 cdImageDestroy( im );
111 im = 0;
112
113 printf( "I just created a simple CGM!!!\n" );
114
115 return 0;
116}
int cdSetEdgeVis(cdImagePtr im, int edvis)
Definition: cd.c:1137
int cdImageCgm(cdImagePtr im, FILE *out)
Definition: cd.c:560
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 cdSetShapeFillAttrib(cdImagePtr im, int instyle, int incolor, int inhatch)
Definition: cd.c:1668
int cdRectangle(cdImagePtr im, int x1, int y1, int x2, int y2)
Definition: cd.c:2235
int cdImageDestroy(cdImagePtr im)
Definition: cd.c:1766
cdImagePtr cdImageCreate(int sx, int sy)
Definition: cd.c:31
int main()
Definition: cdsimple.c:30