This shows you the differences between two versions of the page.
haas:fall2019:c4eng:projects:cos0 [2018/09/24 14:23] – external edit 127.0.0.1 | haas:fall2019:c4eng:projects:cos0 [2019/10/28 13:24] (current) – wedge | ||
---|---|---|---|
Line 1: | Line 1: | ||
<WRAP centeralign round box> | <WRAP centeralign round box> | ||
< | < | ||
- | < | + | < |
</ | </ | ||
Line 13: | Line 13: | ||
* can algorithmically generate a circle of points (x, y coordinate pairs) | * can algorithmically generate a circle of points (x, y coordinate pairs) | ||
- | * can obtain information from the command-line (argc/argv) | ||
* can call functions from a library (gd). | * can call functions from a library (gd). | ||
+ | |||
=====Background===== | =====Background===== | ||
We've spent our time so far this semester covering the basic concepts of programming, | We've spent our time so far this semester covering the basic concepts of programming, | ||
- | Now that we've gotten through | + | Now that we've gotten through |
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, | ||
Line 24: | Line 24: | ||
One piece of that, obviously, is the math. | One piece of that, obviously, is the math. | ||
- | Another | + | Another |
So: we are going to use the gd image processing library to aid us in generating the image. | So: we are going to use the gd image processing library to aid us in generating the image. | ||
=====Program===== | =====Program===== | ||
- | Your task is to write a program that generates an image (PNG file), that is placed in your lab46 webspace for viewing, that does the following: | + | Your task is to write a program that generates an image (PNG file), that is placed in your lab46 webspace |
* uses the gd image library (libgd) | * uses the gd image library (libgd) | ||
- | * reads the following information | + | * prompts for the following information (doing proper |
- | * *(argv+1): | + | * image width (in pixels, ranging from 600-1024) |
- | * *(argv+2): | + | * image height (in pixels, ranging from 800-1280) |
- | * *(argv+3): | + | * circle radius (in pixels, should not exceed half of the smaller of width, height) |
- | * *(argv+4): | + | * center x of circle (a value of 0 should result in auto-centering of x with respect to width) |
- | * *(argv+5): | + | * center y of circle (a value of 0 should result in auto-centering of y with respect to height) |
- | * *(argv+6), if present, will be the name of the output image file produced. If it is absent, assume the default name **cos0.png**. | + | * image width, height is at least 600x800 (can be larger, but not huge, don't go beyond 1024x1280) |
- | * image width, height is at least 600x800 (can be larger, but not huge, don't go beyond 1024x1280)-- and specified on the command-line when running the program | + | * if the correct |
- | * if the information isn't supplied, display an error and exit with non-zero status | + | |
* image resolution must not be square (i.e. **NOT** 800x800, 1000x1000, etc.)-- if it is, display an error and exit with non-zero status | * image resolution must not be square (i.e. **NOT** 800x800, 1000x1000, etc.)-- if it is, display an error and exit with non-zero status | ||
* image has a black background | * image has a black background | ||
Line 49: | Line 48: | ||
* multiple circles (concentric? | * multiple circles (concentric? | ||
* spirals | * spirals | ||
- | * squares should be at least 12x12 (pixels) | + | * squares should be at least 32x32 (pixels) |
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==== | + | =====Grabbing project resources===== |
- | You may make use of the following skeleton program | + | I have prepared a **grabit** for resources related |
- | Note that this code is not in conformance with project specifications, | + | < |
+ | lab46:~/ | ||
+ | make: Entering directory '/ | ||
+ | '/ | ||
+ | '/ | ||
+ | make: Leaving directory '/ | ||
+ | lab46: | ||
+ | </ | ||
- | <code c> | + | At which point you can change into the newly created and populated |
- | /* | + | |
- | * cos0.c | + | |
- | * to create an image (circle of squares). | + | |
- | * | + | |
- | * 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); | + | |
- | } | + | |
- | </ | + | |
=====How to view your image===== | =====How to view your image===== | ||
Line 185: | Line 71: | ||
To view your image in a web browser, simply point it at the following URL: | To view your image in a web browser, simply point it at the following URL: | ||
- | * < | + | * < |
- | ... where " | + | ... where " |
Note that the tilde just prior to your username in the URL is critical and necessary. | 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: | And, of course, your basic compile and clean-up operations: | ||
Line 234: | Line 103: | ||
<cli> | <cli> | ||
- | $ submit | + | $ submit |
- | Submitting | + | Submitting |
-> cos0.c(OK) | -> cos0.c(OK) | ||
- | -> cos0.png(OK) | ||
- | -> http:// | ||
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED | ||
Line 249: | Line 116: | ||
< | < | ||
78: | 78: | ||
- | *:cos0:submit project | + | *:cos0:proper error checking and status reporting performed |
- | *:cos0:level of adequate modification in cos0.c | + | *:cos0:correct variable types and name lengths used [13/13] |
- | *:cos0:level of adequate commenting in cos0.c | + | *:cos0:proper output formatting per specifications |
- | *:cos0:level of adequate indentation in cos0.c | + | *:cos0:runtime tests of submitted program succeed |
- | *: | + | *:cos0:no negative compiler messages |
- | *:cos0:no negative compiler messages [4/4] | + | *:cos0:code is pushed to lab46 repository |
- | *:cos0:circle of squares | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *:cos0:can adjust output file name with optional last argument [4/4] | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
</ | </ | ||
Additionally: | Additionally: | ||
+ | |||
* Solutions not abiding by spirit of project will be subject to a 25% overall deduction | * Solutions not abiding by spirit of project will be subject to a 25% overall deduction | ||
* Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction | * Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction | ||
* Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction | * Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction | ||
- | * Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction | + | * Solutions not organized and easy to read are subject to a 25% overall deduction |