# This function CALLS Eyeball TWICE (once for each eye) to place the pair of eye
ID: 3605807 • Letter: #
Question
# This function CALLS Eyeball TWICE (once for each eye) to place the pair of eyeballs on the screen. Stare must first determine the correct radius and center positions for each eye before calling Eyeball at all. #
def Stare (Canvas,NewColor):
return
In the Stare function (see above), write new code to call Eyeball twice, once for the left eye and once for the right eye, with the correct radius and coordinates for each eye computed from the size of the Canvas. If the width and height of the Canvas are extracted into variables W and H as follows: W = getWidth (Canvas) H = getHeight (Canvas)
Then all the other measurements needed to find the position of the eyeballs are computed as follows: Xleft = 1/4W Xright = 3/4W Y = 1/2H
What remains for Stare to compute is the eyeball radius. The radius R is computed from the minimum (using Python’s min(…,…) function) of Xleft and Y, times , minus 5 pixels. This may seem overly complicated, but doing it this way guarantees that the eyes will always fit onto the screen.
Explanation / Answer
The function will calculate central points of both eyeballs, that is, (Xleft,Y) and (Xright,Y) and also calculates radius R of each eyeball such that they always fix on the canvas.
Then function Eyeball is called twicw with these paramenters.
Code:
def Stare(Canvas, NewColor)
W = getWidth (Canvas)
H = getHeight (Canvas)
Xleft = (1/4)*W
Xright = (3/4)*W
Y = (1/2)*H
R = min(Xleft, ((2*Y)/3)-5)
Eyeball(Xleft,Y,R)
Eyeball(Xright,Y,R)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.