|CS 171 & 171L||Introduction to Computer Science I & Lab||Fall 2017|
Homework Assignment 2
You will modify your program from Homework 1 to use methods and so that the eyes follow the mouse.
Methods for drawing your face
Create a method for drawing your initials. Create a method for drawing your face. For each major facial feature (eye, nose, mouth, head, hair, etc), create a method that draws that feature. Call these from your draw method. Most of your methods will be void with no parameters, with the exception of drawing eyes as described below.
For the eyes, your eye method should take two parameters corresponding to the eye center position (x and y). The same method can be called twice with different actual parameters to draw each eye. Note that a change to the method will cause both eyes to change.
(10 points) Modify your eye method so that the eyes follow the mouse. There will be two case to consider: the mouse is either inside or outside the eye. If the mouse is inside an eye, the position of the pupil/iris will be drawn at the mouse position. Otherwise, the pupil/iris will be drawn along an ellipse that is concentric with the ellipse defining the eye and along a line from the center of the eye to the the mouse position.
For a more realistic drawing, note that the pupil is concentrically located inside the pupil. As the eye moves, it rotates in the socket, altering the position of the pupil, which lets light into the interior of the eye, For this project, you should have a large sclera (white part). The radius of the iris should be smaller than the smallest radius of curvature of the eye. Change your eye shape if needed.
Given a right triangle with legs a and b, the angle t is given by t = tan-1(b/a). Because a might be zero, this can cause a problem in determining the angle. This is avoided by using the atan2 function, Math.atan2(b,a).
Given an ellipse centered at the origin having a width of 2a and a height of 2b, then (acos(t), b sin(t)) is the coordinate of a point along the perimeter of the ellipse with angle t. Note that when a=b, the ellipse is a circle and the point along the circle is given by (a cos(t), a sin(t)).
You may need to convert from variables of type double to type float. You can do this by
float f; double d; d = f; // no problem, widening conversion f = d; // error, narrowing conversion f = (float) d; // correct!
You must use comments in your program. At the top, put your name and assignment number in a comment. Label each major section with a comment. Use whitespace (a blank line or two) to also separate section of your code to improve its readability.
Send me (email@example.com) the following in a pde file as an attachment to an email message with Homework 1 as the subject line.
Copyright © 2017, David A. Reimann. All rights reserved.