haas:fall2020:cprog:projects:cos0
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
haas:fall2020:cprog:projects:cos0 [2020/10/19 16:13] – [How to view your image] wedge | haas:fall2020:cprog:projects:cos0 [2020/10/19 16:13] – [getting started] wedge | ||
---|---|---|---|
Line 52: | Line 52: | ||
Now, gd has functions for drawing circles. You are **NOT** to use them for this project. As I said, this is a circle //of squares//. As such, you will be making use of the **gdImageFilledRectangle()** function. | Now, gd has functions for drawing circles. You are **NOT** to use them for this project. As I said, this is a circle //of squares//. As such, you will be making use of the **gdImageFilledRectangle()** function. | ||
- | |||
- | ====getting started==== | ||
- | You may make use of the following skeleton program to assist you in doing this project. | ||
- | |||
- | Note that this code is not in conformance with project specifications, | ||
- | |||
- | <code c> | ||
- | /* | ||
- | * cos0.c | ||
- | | ||
- | * | ||
- | * To compile: type ' | ||
- | | ||
- | * To execute: ./cos0 ARGS | ||
- | * | ||
- | * Documentation: | ||
- | | ||
- | */ | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | |||
- | // color values | ||
- | // | ||
- | #define BLACK 0 | ||
- | #define BLUE 1 | ||
- | #define GREEN 2 | ||
- | #define RED 3 | ||
- | #define WHITE 4 | ||
- | |||
- | int main(int argc, char **argv) | ||
- | { | ||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Declare variables | ||
- | // | ||
- | char | ||
- | FILE | ||
- | gdImagePtr | ||
- | unsigned int color[5]; | ||
- | unsigned short int wide, high; // image attributes | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Check arguments | ||
- | // | ||
- | if (argc == 2) | ||
- | { | ||
- | outfile | ||
- | fprintf(stdout, | ||
- | } | ||
- | else | ||
- | { | ||
- | outfile | ||
- | sprintf(outfile, | ||
- | } | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // image dimensions | ||
- | // | ||
- | wide = 600; | ||
- | high = 800; | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Create new image of specified wide-ness and high-ness | ||
- | // | ||
- | img = gdImageCreate(wide, | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Some GD color definitions | ||
- | // | ||
- | color[BLACK] | ||
- | color[BLUE] | ||
- | color[GREEN] | ||
- | color[RED] | ||
- | color[WHITE] | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Paint the background black | ||
- | // | ||
- | gdImageFilledRectangle(img, | ||
- | |||
- | / | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Open the file | ||
- | // | ||
- | out = fopen(outfile, | ||
- | if(out | ||
- | { | ||
- | fprintf(stderr, | ||
- | exit(1); | ||
- | } | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Set sane file permissions on image file | ||
- | // | ||
- | chmod (outfile, 0644); | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Send image to file | ||
- | // | ||
- | gdImagePngEx(img, | ||
- | |||
- | ////////////////////////////////////////////////////////////////// | ||
- | // | ||
- | // Close things up | ||
- | // | ||
- | fclose(out); | ||
- | gdImageDestroy(img); | ||
- | |||
- | return(0); | ||
- | } | ||
- | </ | ||
haas/fall2020/cprog/projects/cos0.txt · Last modified: 2020/10/19 16:14 by wedge