Introduction to C++
Jonah Warrenjonah AT parsons DOT edu
http://www.feedtank.com/2005/cpp
MIDTERM
(Please email me if you have any questions.)- Review class code here.
- For your midterm, you are going to create a mini library of 2d drawing functions that will draw shapes in RAW files. You will then create a composition / series of compositions using these basic functions.
- Start with this basic code structure.
- Create a number of drawing functions. For each function you will need to:
- pass in the position you want your shape (a coordinate pair)
- pass in the size (if appropriate - some you just may pass in a series of coordinate pairs (x0,y0, x1,y1...))
- pass in the grayscale value you want to draw the shape (unsigned char)
- pass in the imgArray (you will be changing pixel values in this array)
- drawPoint();
- drawFilledRect();
- drawLine(); (see hint below)
- drawRect();
- drawTriangle();
- drawPolygon(); (overload this function, so that you can call it with 4, 5 or 6 coordinates).
- Here is an example of a function that draws a horizontal line. Your functions will look similar.
- You will be drawing everything to your imgArray, which means you need to translate coordinate pairs to spots in the array. (Translate from 2d grid to 1d list). To do this, you can use the following formula to go from coordinates to array position: (x,y) ---> ((y*WIDTH)+x))
- In your line function, instead of using raster.setPixel, you are going to be changing values in your imgArray.
The line function is important and most difficult. Try to tackle this first, as you will use it in your drawRect(), drawTriangle() and drawPolygon() functions. Check out this page to get the lowdown on y=mx+b. Read at least up to step2. You can alter the code it gives for lineImproved() to make your own line function. You will need to use the iround() function included in the midterm_structure.cpp code instead of round(). You will also need to include 'math.h' as done in this file in order to use abs() and floor() functions.
After you have made all your functions, have fun with them. Use for loops. Use modulo (%). Try using recursion to make interesting patterns with your shapes. Use RAW files that are pictures and draw a shape for each pixel. Make a bunch of drawings with them. Print them out. Don't print them out. Come up with creative applications of these functions. Create 3-5 compositions or more. Create one super duper crazy one. Whatever you feel like. We will look at them as a class when we get back from break, so make them presentable... on a website, or printed out.
HINTS: