This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2017:cprog:projects:cos0 [2017/03/11 22:31] – [Program] wedge | haas:spring2017:cprog:projects:cos0 [2017/03/20 14:45] (current) – [How to view your image] wedge | ||
---|---|---|---|
Line 22: | Line 22: | ||
Now that we've gotten through all of them, it is time to start applying those concepts so that deeper and further familiarity can be gained. This project is one such attempt at that. | Now that we've gotten through all of them, it is time to start applying those concepts so that deeper and further familiarity can be gained. This project is one such attempt at that. | ||
- | We all know what a circle is, and in various math classes we've even explored various methods for doing things with circles (they have a radius, a circumference, | + | We all know what a circle is, and in various math classes we've even explored various methods for doing things with circles (they have a radius, a circumference, |
One piece of that, obviously, is the math. | One piece of that, obviously, is the math. | ||
Line 62: | Line 62: | ||
<code c> | <code c> | ||
/* | /* | ||
- | | + | |
- | | + | |
* | * | ||
- | * To compile: | + | * To compile: |
- | * To execute: | + | |
- | | + | * To execute: ./ |
* | * | ||
- | | + | |
+ | | ||
*/ | */ | ||
#include < | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
+ | #include < | ||
#include < | #include < | ||
Line 86: | Line 88: | ||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||
{ | { | ||
- | | + | ////////////////////////////////////////////////////////////////// |
- | FILE | + | // |
- | gdImagePtr | + | // Declare variables |
- | unsigned int color[5]; | + | // |
- | unsigned short int wide, high; | + | |
+ | FILE | ||
+ | gdImagePtr | ||
+ | unsigned int color[5]; | ||
+ | unsigned short int wide, high; // image attributes | ||
- | | + | ////////////////////////////////////////////////////////////////// |
- | { | + | // |
- | outfile = *(argv+1); | + | // Check arguments |
- | fprintf(stdout, | + | // |
- | } | + | |
- | else | + | { |
- | { | + | outfile |
- | outfile = (char *) malloc (sizeof(char) * 64); | + | fprintf(stdout, |
- | | + | } |
- | } | + | else |
+ | { | ||
+ | outfile | ||
+ | | ||
+ | } | ||
- | | + | ////////////////////////////////////////////////////////////////// |
- | // | + | // |
- | wide = 800; | + | |
- | high = 600; | + | // |
+ | wide = 600; | ||
+ | high = 800; | ||
- | | + | ////////////////////////////////////////////////////////////////// |
- | // | + | // |
- | img = gdImageCreate(wide, | + | |
+ | // | ||
+ | img | ||
- | | + | |
- | // | + | // |
- | color[BLACK] | + | // Some GD color definitions |
- | color[BLUE] | + | // |
- | color[GREEN] | + | color[BLACK] |
- | color[RED] | + | color[BLUE] |
- | color[WHITE] | + | color[GREEN] |
+ | color[RED] | ||
+ | color[WHITE] | ||
- | | + | ////////////////////////////////////////////////////////////////// |
- | // | + | // |
- | gdImageFilledRectangle(img, | + | |
+ | // | ||
+ | gdImageFilledRectangle(img, | ||
/ | / | ||
Line 130: | Line 148: | ||
| | ||
- | | + | ////////////////////////////////////////////////////////////////// |
- | // | + | // |
- | if((out = fopen(outfile, | + | |
- | { | + | // |
- | fprintf(stderr, | + | out |
- | exit(1); | + | if(out |
- | } | + | { |
+ | fprintf(stderr, | ||
+ | exit(1); | ||
+ | } | ||
- | | + | |
- | // | + | // |
- | | + | // Set sane file permissions on image file |
+ | // | ||
+ | | ||
- | | + | //////////////////////////////////////////////////////////////// |
- | // | + | // |
- | | + | // Send image to file |
- | | + | // |
+ | gdImagePngEx(img, out, -1); | ||
- | | + | ////////////////////////////////////////////////////////////////// |
+ | // | ||
+ | // Close things up | ||
+ | // | ||
+ | fclose(out); | ||
+ | gdImageDestroy(img); | ||
+ | |||
+ | | ||
} | } | ||
</ | </ | ||
+ | |||
+ | =====How to view your image===== | ||
+ | When you have a functioning project and want to view the images generated, you need to make sure they are deployed into your **public_html/ | ||
+ | |||
+ | To view your image in a web browser, simply point it at the following URL: | ||
+ | |||
+ | * < | ||
+ | |||
+ | ... where " | ||
+ | |||
+ | Note that the tilde just prior to your username in the URL is critical and necessary. | ||
+ | |||
+ | =====Grabit Integration===== | ||
+ | I rigged up a skeleton file in a **grabit** project to kickstart your efforts. | ||
+ | |||
+ | To " | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | make: Entering directory '/ | ||
+ | ‘/ | ||
+ | ‘/ | ||
+ | make: Leaving directory '/ | ||
+ | lab46: | ||
+ | lab46: | ||
+ | Makefile | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | And, of course, your basic compile and clean-up operations: | ||
+ | |||
+ | * **make**: compile everything | ||
+ | * **make debug**: compile everything with debug support | ||
+ | * **make clean**: remove all binaries | ||
+ | |||
+ | Just another "nice thing" we deserve. | ||
+ | |||
+ | NOTE: You do NOT want to do this on a populated **cos0** project directory-- it will overwrite files. Only do this on an empty directory. | ||
=====Submission===== | =====Submission===== | ||
Line 177: | Line 246: | ||
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. | You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. | ||
+ | |||
+ | What I'll be looking for: | ||
+ | |||
+ | < | ||
+ | 78: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *:cos0:no negative compiler messages [4/4] | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *:cos0:can adjust output file name with optional last argument [4/4] | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | </ |