logo CodeStepByStep logo

GoogleyEyes

Write a graphical program named GoogleyEyes as described on this page.

Initial appearance: Set the window's canvas size to be 500x400 with a cyan background. When the program runs, draw two eyes. Each eye is 100x100 pixels in size, filled in white, with a black outline. The first eye is drawn with the top-left position of (x=70, y=65) and the second eye is immediately to its right. Each eye has a pupil drawn as a black filled oval of size 20x20, horizontally centered within each eye, vertically at the top of each eye.

screenshot

Mouse movement: (1) If the user moves the mouse within the window, the pupils move to "follow" the cursor vertically. If the mouse cursor is above the top of the eyes, the pupils move "up" to the top of the eyes. If the cursor is vertically within the eyes' y-values, the pupils move to the center of the eyes. If the mouse is below the bottom of the eyes, the pupils look "down" to the bottom the eyes. The pupils do not move horizontally; the mouse movement code does not need to examine the mouse's x-position.

screenshot screenshot screenshot

Mouse clicks: If the user clicks the mouse inside an eye, that eye's pupil should toggle its fill color between black and red. If the pupil is black, make it red; otherwise make it black. If the user clicks elsewhere, nothing happens.

screenshot screenshot

Constants: Use the four integer constants EYE_X, EYE_Y, SIZE, and PUPIL for the eye positions and eye/pupil sizes in pixels. If these constants were changed, your program should update properly: the eyes and pupils would use the new sizes, appear next to each other horizontally, and the mouse move/click behavior would still work. You may assume that the constants will be set to reasonable values, both positive integers with the pupil size less than the eye size.

Constraints: Do not make assumptions about the window's size; it should work for any window of reasonable size.

This exercise does not have any test cases associated with it. You can look at this exercise and try to write your own solution on your computer in a text editor, but you cannot submit it here for testing. We're sorry for the inconvenience.

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.