PLplot: color16.c Source File

PLplot 5.15.0

color16.c
Go to the documentation of this file.
1 //
2 // Color16 is a test program that is part of the CGM Draw Library.
3 // It Will write out a CGM file that allocates a 16 color pallete
4 // using the function cdImageColor16. These correspond to the 16
5 // standard Windows colors.
6 //
7 //
8 // color16.c: test program for the cgmdraw module.
9 //
10 // Written by G. Edward Johnson <mailto:lorax@nist.gov>
11 // Date: April 1996
12 // Copyright: cd software produced by NIST, an agency of the
13 // U.S. government, is by statute not subject to copyright
14 // in the United States. Recipients of this software assume all
15 // responsibilities associated with its operation, modification
16 // and maintenance.
17 //
18 //
19
20
21 #ifndef NOMALLOCH
22 #include <malloc.h>
23 #endif
24 #include <stdio.h>
25 #include <math.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include "defines.h"
29 #include "cd.h"
30
31
32 int main()
33 {
34 cdImagePtr im;
35 FILE *outf;
36
37
38 // Create an image 500 pixels high by 400 pixels wide
39 im = cdImageCreate( 400, 500 );
40
41 // allocate the 16 windows colors
42 if ( -1 == cdImageColor16( im ) )
43 return 1;
44
45 // Set the fill attributes
46 // fill=solid, colorindex=0, hatch=no change
47 if ( !( cdSetShapeFillAttrib( im, 1, 0, 1 ) ) )
48 return 1;
49
50 // set the text attributes
51 // font=helvetica, colorindex=1, size=25
52 if ( !( cdSetTextAttrib( im, 5, 1, 25 ) ) )
53 return 1;
54
55 // The first color index is white, so lets draw a box around it
56 // edge=solid, width=1, color=1 (black), visible=yes
57 cdSetShapeEdgeAttrib( im, 1, 1, 1, 1 );
58
59
60 // Draw a rectangle (10,450) is upper left, (35,425) is lower right
61 if ( !( cdRectangle( im, 10, 450, 35, 425 ) ) )
62 return 1;
63 // Label it
64 if ( !( cdText( im, 40, 425, "Color Index: 0" ) ) )
65 return 1;
66
67 // Make the edges invisible
68 if ( !( cdSetEdgeVis( im, 0 ) ) )
69 return 1;
70
71
72 // Set the fill color
73 if ( !( cdSetFillColor( im, 1 ) ) )
74 return 1;
75 // Draw a rectangle
76 if ( !( cdRectangle( im, 10, 400, 35, 375 ) ) )
77 return 1;
78 // Label it
79 if ( !( cdText( im, 40, 375, "Color Index: 1" ) ) )
80 return 1;
81
82 // Set the fill color
83 if ( !( cdSetFillColor( im, 2 ) ) )
84 return 1;
85 // Draw a rectangle
86 if ( !( cdRectangle( im, 10, 350, 35, 325 ) ) )
87 return 1;
88 // Label it
89 if ( !( cdText( im, 40, 325, "Color Index: 2" ) ) )
90 return 1;
91
92 // Set the fill color
93 if ( !( cdSetFillColor( im, 3 ) ) )
94 return 1;
95 // Draw a rectangle
96 if ( !( cdRectangle( im, 10, 300, 35, 275 ) ) )
97 return 1;
98 // Label it
99 if ( !( cdText( im, 40, 275, "Color Index: 3" ) ) )
100 return 1;
101
102 // Set the fill color
103 if ( !( cdSetFillColor( im, 4 ) ) )
104 return 1;
105 // Draw a rectangle
106 if ( !( cdRectangle( im, 10, 250, 35, 225 ) ) )
107 return 1;
108 // Label it
109 if ( !( cdText( im, 40, 225, "Color Index: 4" ) ) )
110 return 1;
111
112 // Set the fill color
113 if ( !( cdSetFillColor( im, 5 ) ) )
114 return 1;
115 // Draw a rectangle
116 if ( !( cdRectangle( im, 10, 200, 35, 175 ) ) )
117 return 1;
118 // Label it
119 if ( !( cdText( im, 40, 175, "Color Index: 5" ) ) )
120 return 1;
121
122 // Set the fill color
123 if ( !( cdSetFillColor( im, 6 ) ) )
124 return 1;
125 // Draw a rectangle
126 if ( !( cdRectangle( im, 10, 150, 35, 125 ) ) )
127 return 1;
128 // Label it
129 if ( !( cdText( im, 40, 125, "Color Index: 6" ) ) )
130 return 1;
131
132 // Set the fill color
133 if ( !( cdSetFillColor( im, 7 ) ) )
134 return 1;
135 // Draw a rectangle
136 if ( !( cdRectangle( im, 10, 100, 35, 75 ) ) )
137 return 1;
138 // Label it
139 if ( !( cdText( im, 40, 75, "Color Index: 7" ) ) )
140 return 1;
141
142 // Set the fill color
143 if ( !( cdSetFillColor( im, 8 ) ) )
144 return 1;
145 // Draw a rectangle
146 if ( !( cdRectangle( im, 210, 450, 235, 425 ) ) )
147 return 1;
148 // Label it
149 if ( !( cdText( im, 240, 425, "Color Index: 8" ) ) )
150 return 1;
151
152 // Set the fill color
153 if ( !( cdSetFillColor( im, 9 ) ) )
154 return 1;
155 // Draw a rectangle
156 if ( !( cdRectangle( im, 210, 400, 235, 375 ) ) )
157 return 1;
158 // Label it
159 if ( !( cdText( im, 240, 375, "Color Index: 9" ) ) )
160 return 1;
161
162 // Set the fill color
163 if ( !( cdSetFillColor( im, 10 ) ) )
164 return 1;
165 // Draw a rectangle
166 if ( !( cdRectangle( im, 210, 350, 235, 325 ) ) )
167 return 1;
168 // Label it
169 if ( !( cdText( im, 240, 325, "Color Index: 10" ) ) )
170 return 1;
171
172 // Set the fill color
173 if ( !( cdSetFillColor( im, 11 ) ) )
174 return 1;
175 // Draw a rectangle
176 if ( !( cdRectangle( im, 210, 300, 235, 275 ) ) )
177 return 1;
178 // Label it
179 if ( !( cdText( im, 240, 275, "Color Index: 11" ) ) )
180 return 1;
181
182 // Set the fill color
183 if ( !( cdSetFillColor( im, 12 ) ) )
184 return 1;
185 // Draw a rectangle
186 if ( !( cdRectangle( im, 210, 250, 235, 225 ) ) )
187 return 1;
188 // Label it
189 if ( !( cdText( im, 240, 225, "Color Index: 12" ) ) )
190 return 1;
191
192 // Set the fill color
193 if ( !( cdSetFillColor( im, 13 ) ) )
194 return 1;
195 // Draw a rectangle
196 if ( !( cdRectangle( im, 210, 200, 235, 175 ) ) )
197 return 1;
198 // Label it
199 if ( !( cdText( im, 240, 175, "Color Index: 13" ) ) )
200 return 1;
201
202 // Set the fill color
203 if ( !( cdSetFillColor( im, 14 ) ) )
204 return 1;
205 // Draw a rectangle
206 if ( !( cdRectangle( im, 210, 150, 235, 125 ) ) )
207 return 1;
208 // Label it
209 if ( !( cdText( im, 240, 125, "Color Index: 14" ) ) )
210 return 1;
211
212 // Set the fill color
213 if ( !( cdSetFillColor( im, 15 ) ) )
214 return 1;
215 // Draw a rectangle
216 if ( !( cdRectangle( im, 210, 100, 235, 75 ) ) )
217 return 1;
218 // Label it
219 if ( !( cdText( im, 240, 75, "Color Index: 15" ) ) )
220 return 1;
221
222 // now put a little thing at the bottom of the picture
223 if ( !cdText( im, 5, 10, "Colors allocated by cdImageColor16" ) )
224 return 1;
225
226 // now write the file out, lets call it color16.cgm
227 outf = fopen( "color16.cgm", "wb" );
228 if ( !outf )
229 return 1;
230 cdImageCgm( im, outf );
231 fclose( outf );
232 outf = 0;
233
234 // Remember to destroy the image when you are done
235 cdImageDestroy( im );
236 im = 0;
237
238 printf( "CGM with 16 color colortable generated as color16.cgm\n" );
239
240 return 0;
241 }
cdImageCgm
int cdImageCgm(cdImagePtr im, FILE *out)
Definition: cd.c:560
cdRectangle
int cdRectangle(cdImagePtr im, int x1, int y1, int x2, int y2)
Definition: cd.c:2235
cdImageStruct
Definition: cd.h:60
cdSetEdgeVis
int cdSetEdgeVis(cdImagePtr im, int edvis)
Definition: cd.c:1137
cdImageDestroy
int cdImageDestroy(cdImagePtr im)
Definition: cd.c:1766
cdText
int cdText(cdImagePtr im, int x, int y, const char *ts)
Definition: cd.c:2945
cdSetTextAttrib
int cdSetTextAttrib(cdImagePtr im, int font, int color, int height)
Definition: cd.c:1720
defines.h
cdSetShapeFillAttrib
int cdSetShapeFillAttrib(cdImagePtr im, int instyle, int incolor, int inhatch)
Definition: cd.c:1668
cdImageColor16
int cdImageColor16(cdImagePtr im)
Definition: cd.c:1989
main
int main()
Definition: color16.c:32
cd.h
cdSetFillColor
int cdSetFillColor(cdImagePtr im, int incolor)
Definition: cd.c:822
cdSetShapeEdgeAttrib
int cdSetShapeEdgeAttrib(cdImagePtr im, int edtype, int edwidth, int edcolor, int edvis)
Definition: cd.c:1693
cdImageCreate
cdImagePtr cdImageCreate(int sx, int sy)
Definition: cd.c:31