/* CSC 15 Individual Programming Assignment Due Friday 3/2/01 -- This assignment MUST be completed individually! -- For this assignment you are to draw a stick figure like the one shown in class. It should have a round head, nose, mouth, torso, arms, and legs. You may add other features as you see fit. First download this file from the class homepage and make sure you can compile and run it. (remember to source useqt - go back to first lab if you forgot.) Most of the code has already been set up for you. Go to the line marked with *********** and start there. The term 'brush' is an "object" that manages the drawing of shapes onto a display area. It consists of many functions that controls how drawing is to be done. This is your first exposure to "object oriented" programming, expect you'll be using objects that are already defined for you (by the Qt library). Here's all you need to know: brush->drawLine(x1,y2,x2,y2); : this statement draws a line between the two point coordinates x1,y1 and x2,y2 brush->drawRect(x,y,w,h); : This statement draws a rectangle with upper left corner at coordinate x,y, and of width w and height h. Note that the last two argument does not represent a coordinate; they are relative to x and y. brush->drawEllipse(x,y,w,h); : x,y,w, and h are used the same way as they are in drawRect, expect that a ellipse will be drawn in the area. To draw a circle, make sure that w and h are the same. To draw a circle with its center at x0,y0 and a radius of r, use brush->drawEllipse(x0-r,y0-r,2*r,2*r); brush->drawArc(x,y,w,h,sa,al); : Draws an arc - part of an ellipse. The first four parameters define an ellipse as before. sa is the start angle of the arc (0 will be horizontal, 90 vertical). al is the "arc length" expressed in units of 1/16 of degrees. Confusing? Try it and see what happens!!! brush->setPen(QPen(blue,2)); : this statement will set the color (in this case blue) and size of the pen used to draw *lines*. The bigger the number, the thicker the lines will be. The default color is black. brush->setBrush(QBrush(green,SolidPattern)); : this statement tells brush to, when it's drawing a rectangle or ellipse, to fill in the area with the named color (in this case green). Note, if the "QPen" color is blue, and you set the fill color to be green, then drawing a rectangle will result in a green rectangle with a blue border. In order to draw a shape with uniform color, you need to set both the "Pen" and the "Brush" to the same color. The colors you can use for setPen and setBrush include black, white, red, green, blue, cyan, yellow, gray, and magenta. brush->setBrush(QBrush(NoBrush)); : this statement will turn off the filling in of areas. After this statement, if you draw a rectangle only the border will be drawn. Remember that the size of the window is 400X400 pixels - this means that the range of the x and y coordinates are 0-399. coordinate 0,0 represents the top left hand corner of the window. coordinate 0,399 represents the lower left hand corner, etc... For commenting, make clear as to what part of the anatomy you're drawing with each command. If you have additional code, you need to comment on what they're for too. Think about using variables in your program. This will allow you to modify the program by just changing the value of a few variables (instead of every line). Also make sure that all variables are clearly commented. ********** USE VARIABLES ************ You need to use variables to hold the values of the coordinates and dimensions of your figure. By using variables, you can change various attributes of the figure by just changing the value of one or two varibles, without touching the rest of the program. Refer to the diagram and demonstration given in class. ********** COMPILATION INSTRUCTIONS ******** 1. download this file and "drawing.C" from the class homepage 2. do "source useqt" then "moc drawing.C -o drawing" 3. write the program 4. do qtcompile figure.C, or whatever file you want to call it HAND IN: clear sketch of figure with calculated coordinates on paper print out of picture produced by program source code of you program, with these instructions deleted */ #include "drawing.C" // draw a diamond with center coordinates at x,y, and size s: void mywindow::drawDiamond(int x, int y, int s) { brush->drawLine(x-s,y,x,y-s); // left to top brush->drawLine(x,y-s,x+s,y); // top to right brush->drawLine(x+s,y,x,y+s); // right to bottom brush->drawLine(x,y+s,x-s,y); // bottom to left } // end drawDiamond void mywindow::drawMyPicture() // draws diamonds { int x; int y; int s; // center coordinates and scale factor x = 50; y=60; s = 32; brush->setPen(QPen(red,2)); drawDiamond(50,60,32); while (x<400) { x = x + 10; drawDiamond(x,y,s); } } // end of drawMyPicture