User Tools

Site Tools


Sidebar

projects

wcp1 (due 20220824)
fwf0 (due 20220831)
ntr0 (due 20220831)
pct1 (bonus; due 20220831)
wcp2 (due 20220831)
dtr0 (due 20220907)
pct2 (due 20220907)
pct3 (bonus; due 20220907)
wcp3 (due 20220907)
sof0 (due 20220914)
wcp4 (due 20220914)
pct4 (due 20220915)
dow0 (due 20220921)
wcp5 (due 20220921)
pct5 (bonus; due 20220922)
cnv0 (due 20220928)
gfo0 (due 20220928)
wcp6 (due 20220928)
pct6 (due 20220929)
cnv1 (due 20221005)
pct7 (bonus; due 20221005)
wcp7 (due 20221005)
bwp1 (bonus; due 20221019)
cbf0 (due 20221019)
pct8 (due 20221019)
wcp8 (due 20221019)
pct9 (bonus; due 20221026)
wcp9 (due 20221026)
gfo1 (due 20221102)
pctA (due 20221102)
sam0 (due 20221102)
wcpA (due 20221102)
pctB (bonus; due 20221109)
wcpB (due 20221109)
oop0 (due 20221110)
oop1 (due 20221116)
pctC (due 20221116)
wcpC (due 20221116)
bwp2 (bonus; due 20221201)
oop2 (due 20221201)
pctD (bonus; due 20221201)
wcpD (bonus; due 20221201)
pctE (bonus; due 20221207)
wcpE (bonus; due 20221207)
gfo2 (due 20221208)
EoCE (due 20221219)
haas:fall2022:cprog:projects:cos0

Corning Community College

CSCS1320 C/C++ Programming

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 obtain information from the command-line (argc/argv)
  • 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 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, a diameter), but how would we enable the computer to draw a circle?

One piece of that, obviously, is the math.

Another piece 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 for viewing, that does the following:

  • uses the gd image library (libgd)
  • reads the following information from the command-line (lacking this information should result in an error):
    • *(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 600×800 (can be larger, but not huge, don't go beyond 1024×1280)– and specified on the command-line when running the program
    • if the 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 12×12 (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.

Grabit Integration

I rigged up a skeleton file in a grabit project to kickstart your efforts.

To “grab” it:

lab46:~/src/SEMESTER/cprog$ grabit cprog cos0
make: Entering directory '/var/public/SEMESTER/cprog/cos0'
‘/var/public/SEMESTER/cprog/cos0/Makefile’ -> ‘/home/USERNAME/src/SEMESTER/cprog/cos0/Makefile’
‘/var/public/SEMESTER/cprog/cos0/cos0.c’ -> ‘/home/USERNAME/src/SEMESTER/cprog/cos0/cos0.c’
make: Leaving directory '/var/public/SEMESTER/cprog/cos0'
lab46:~/src/SEMESTER/cprog$ cd cos0
lab46:~/src/SEMESTER/cprog/cos0$ ls
Makefile  cos0.c
lab46:~/src/SEMESTER/cprog/cos0$ 

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.

How to view the picture

Depending on your computing setup, choose the most practical means of viewing your program's image output:

Raspberry Pi desktop

You've got a monitor and keyboard hooked up to your pi that you are using (preferred method for class).

Open a file browser, web browser, or image viewer and navigate to/open up your cos0.png image in your ~/src/SEMESTER/DESIG/cos0/ directory.

Rinse and repeat as you go through revisions.

Raspberry Pi command-line via SSH/MOSH

You don't have a monitor, so you are logging into your pi remotely (doable, and good intra-system practice)

We start by running a successfully-compiled cos0:

yourpi:~/src/SEMESTER/DESIG/cos0$ ./cos0

… which will produce an image (cos0.png); You want to put this in your web space (with the proper permissions set), so you can view it in a web browser:

yourpi:~/src/SEMESTER/DESIG/cos0$ scp cos0.png yourusername@lab46.g7n.org:public_html/

Note that you may be prompted for your lab46 password.

Then over on lab46, run this:

lab46:~$ chmod 0644 ~/public_html/cos0.png

Then, point a web browser at the following URL:

NOTE: sometimes the web browser caches previous results, you may have to refresh a few times on revisions to get changes to manifest.

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:

lab46:~/src/SEMESTER/DESIG/cos0$ make submit

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:

91:cos0:final tally of results (91/91)
*:cos0:no negative compiler messages for program [13/13]
*:cos0:post generated image to #desig [13/13] 
*:cos0:grabit on the code on lab46 by Sunday before deadline [13/13]
*:cos0:cos0.c code adequately modified per project requirements [39/39]
*:cos0:updated 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/fall2022/cprog/projects/cos0.txt · Last modified: 2021/10/03 20:02 by 127.0.0.1