User Tools

Site Tools


Sidebar

projects

ntr0 (due 20200826)
pct1 (bonus; due 20200821)
wcp1 (due 20200821)
pct2 (due 20200826)
wcp2 (due 20200826)
lob0 (due 20200902)
pct3 (bonus; due 20200902)
wcp3 (due 20200902)
led0 (due 20200909)
pct4 (bonus; due 20200909)
wcp4 (due 20200909)
led1 (due 20200916)
pct5 (bonus; due 20200916)
wcp5 (due 20200916)
led2 (due 20200923)
pct6 (due 20200923)
wcp6 (due 20200923)
iwb0 (due 20200930)
pct7 (bonus; due 20200930)
wcp7 (due 20200930)
iwb1 (due 20201007)
pct8 (due 20201007)
wcp8 (due 20201007)
iwb2 (due 20201014)
gfo0 (due 20201014)
pct9 (bonus; due 20201014)
wcp9 (due 20201014)
clr0 (due 20201021)
pctA (due 20201021)
wcpA (due 20201021)
clr1 (due 20201028)
pctB (bonus; due 20201028)
wcpB (due 20201028)
clr2 (due 20201111)
pctC (due 20201104)
wcpC (due 20201104)
pctD (bonus; due 20201111)
wcpD (bonus; due 20201111)
pctE (bonus; due 20201118)
wcpE (bonus; due 20201118)
eoce (due 20201125)
haas:fall2020:c4eng:projects:cos0

Corning Community College

ENGR1050 C for Engineers

Project: IMAGE PROCESSING - CIRCLE OF SQUARES (cos0)

Objective

To apply our existing knowledge of programming constructs in the application of a specific end result: a program that utilizes an image processing library to produce an image of a circle, constructed of squares.

Prerequisites/Corequisites

In addition to the new skills required on previous projects, to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • can algorithmically generate a circle of points (x, y coordinate pairs)
  • can call functions from a library (gd).

Background

We've spent our time so far this semester covering the basic concepts of programming, in C. Variables, selection statements, iteration, functions, structs, etc.

Now that we've gotten through a good deal 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, a diameter), but how would we enable the computer to draw a circle?

One piece of that, obviously, is the math.

Another aspect of that is the programmatic piece. A circle implies something visual. On the computer that means an image.

So: we are going to use the gd image processing library to aid us in generating the image.

Program

Your task is to write a program that generates an image (PNG file), that is placed in your lab46 webspace (~/public_html/cos0/) for viewing, that does the following:

  • uses the gd image library (libgd)
  • prompts for the following information (doing proper error and range checks as appropriate):
    • image width (in pixels, ranging from 600-1024)
    • image height (in pixels, ranging from 800-1280)
    • circle radius (in pixels, should not exceed half of the smaller of width, height)
    • center x of circle (a value of 0 should result in auto-centering of x with respect to width)
    • center y of circle (a value of 0 should result in auto-centering of y with respect to height)
  • image width, height is at least 600×800 (can be larger, but not huge, don't go beyond 1024×1280)
    • if the correct information isn't supplied, display an error and exit with non-zero status
    • image resolution must not be square (i.e. NOT 800×800, 1000×1000, etc.)– if it is, display an error and exit with non-zero status
  • image has a black background
  • image has an outer border of a color other than background and the circle (unless circle is multiple colors, then the border could be one of the contained colors).
  • draws a circle out of squares
    • circle must be at least 1 color (that isn't the same as the background), but bonus consideration would be given for any of the following:
      • multi-colored (think gradient) circle
      • multiple circles (concentric?)
      • spirals
    • squares should be at least 32×32 (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.

Grabbing project resources

I have prepared a grabit for resources related to this project. To obtain:

lab46:~/src/c4eng$ grabit c4eng cos0
make: Entering directory '/var/public/fall2019/c4eng/cos0'
'/var/public/fall2019/c4eng/cos0/Makefile' -> '/home/wedge/src/c4eng/cos0/Makefile'
'/var/public/fall2019/c4eng/cos0/cos0.c' -> '/home/wedge/src/c4eng/cos0/cos0.c'
make: Leaving directory '/var/public/fall2019/c4eng/cos0'
lab46:~/src/c4eng$ 

At which point you can change into the newly created and populated cos0 directory.

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/ directory.

To view your image in a web browser, simply point it at the following URL:

  • https://lab46.g7n.org/~USERNAME/DIRECTORY/IMAGE.png

… where “USERNAME” is your lab46 username (in lowercase), “DIRECTORY” will be the name of the project ('cos0'), and “IMAGE” is the name of your png file (likely also in lowercase, such as 'cos0.png').

Note that the tilde just prior to your username in the URL is critical and necessary.

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

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
  • Output must be correct, and resemble the form given in the sample output above.
  • Code must be nicely and consistently indented (you may use the indent tool)
  • Code must utilize the algorithm presented above
  • Code must be commented
    • have a properly filled-out comment banner at the top
    • have at least 20% of your program consist of //-style descriptive comments
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool.

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

$ submit c4eng cos0 cos0.c
Submitting c4eng project "cos0":
    -> cos0.c(OK)

SUCCESSFULLY SUBMITTED

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:final tally of results (78/78)
*:cos0:proper error checking and status reporting performed [13/13]
*:cos0:correct variable types and name lengths used [13/13]
*:cos0:proper output formatting per specifications [13/13]
*:cos0:runtime tests of submitted program succeed [13/13]
*:cos0:no negative compiler messages for program [13/13]
*:cos0:code is pushed to lab46 repository [13/13]

Additionally:

  • 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 indentation to promote scope and clarity will be subject to a 25% overall deduction
  • Solutions not organized and easy to read are subject to a 25% overall deduction
haas/fall2020/c4eng/projects/cos0.txt · Last modified: 2019/10/28 13:24 by 127.0.0.1