======GD Polygons======
=====Code=====
#include
#include
#include
#include
// color values
//
#define BLACK 0
#define GRAY 1
#define VIOLET 2
#define INDIGO 3
#define BLUE 4
#define GREEN 5
#define YELLOW 6
#define ORANGE 7
#define RED 8
#define WHITE 9
#define DARKGREEN 10
int main(int argc, char **argv)
{
FILE *out; // output file pointer
char *outfile; // output file name
gdImagePtr img; // GD Image Construct
gdPoint points[3]; // Points for a Polygon
unsigned int color[11]; // color array
unsigned short int wide, high, // useful image and
x, y; // coordinate variables
if (argc == 2)
{
outfile = *(argv+1);
}
else
{
outfile = (char *) malloc (sizeof(char) * 10);
strcpy(outfile, "image.png");
}
fprintf(stdout, "Using '%s' as output filename\n", outfile);
wide = 800;
high = 600;
img = gdImageCreateTrueColor(wide, high);
// My GD color definitions
//
color[BLACK] = gdImageColorAllocate(img, 0, 0, 0);
color[BLUE] = gdImageColorAllocate(img, 0, 0, 255);
color[GREEN] = gdImageColorAllocate(img, 0, 255, 0);
color[DARKGREEN] = gdImageColorAllocate(img, 51, 107, 0);
color[RED] = gdImageColorAllocate(img, 255, 0, 0);
color[GRAY] = gdImageColorAllocate(img, 204, 204, 204);
color[WHITE] = gdImageColorAllocate(img, 255, 255, 255);
/* Draw a triangle. */
points[0x00].x = (wide / 2);
points[0x00].y = 0;
points[0x01].x = wide;
points[0x01].y = high;
points[0x02].x = 0;
points[0x02].y = high;
/* Paint it in white */
gdImageFilledPolygon(img, points, 3, color[GREEN]);
/* Outline it in red; must be done second */
gdImagePolygon(img, points, 3, color[RED]);
// Output the data
//
out = fopen(outfile, "wb");
gdImagePngEx(img, out, -1);
// Close things up
//
fclose(out);
gdImageDestroy(img);
return(0);
}
=====More Polygons=====
If we made another gdPoint array (points2), what would that following code produce a likeness of?
points2[0x00].x = (wide / 2);
points2[0x00].y = (high / 2) - 100;
points2[0x01].x = (wide / 2) + 200;
points2[0x01].y = (high / 2) + 100;
points2[0x02].x = (wide / 2) - 200;
points2[0x02].y = (high / 2) + 0;
points2[0x03].x = (wide / 2) + 200;
points2[0x03].y = (high / 2) + 0;
points2[0x04].x = (wide / 2) - 200;
points2[0x04].y = (high / 2) + 100;
points2[0x05].x = (wide / 2) + 0;
points2[0x05].y = (high / 2) - 100;
=====Combining Shapes=====
Write C programs that creates likenesses of the following (don't worry about shading- just see if you can use your skills to recreate these images, and to make additional images of your liking):
{{http://www.corning-cc.edu/images/corning_community_college_flag_logo_170.gif}}
{{http://www.inkity.com/catalog/img/3/3734.jpg}}
{{http://4.bp.blogspot.com/_BVYzhvN_FZc/TMDCwcFM4FI/AAAAAAAAAfg/KsqNqjfvhNw/s1600/red+white+blue+star.JPG}}
{{http://noobproguide.files.wordpress.com/2012/09/triforce.jpg?w=640&h=468}}
{{http://versus-software.com/blog/wp-content/uploads/2011/11/8_bit_Mario_sprite_by_gotbored27.png}}