# William T. Verts - Lab #2 - Greebles / Anime Eyes #-------------------------------------------------------------- # Helper function to round coordinates to the nearest pixel. #-------------------------------------------------------------- def INT(N): return int(round(N)) #-------------------------------------------------------------- # These functions paint ellipses or filled ellipses at center # with X-radius Xr and Y-radius Yr and color NewColor, # as well as filled circles of radius R. # Xc, Yc, Xr, Yr, and R may all be floats. #-------------------------------------------------------------- def addEllipse (Canvas,Xc,Yc,Xr,Yr,NewColor=black): return #-------------------------------------------------------------- def addEllipseFilled (Canvas,Xc,Yc,Xr,Yr,NewColor=black): return #-------------------------------------------------------------- def addCircleFilled (Canvas,Xc,Yc,R,NewColor=black): return #-------------------------------------------------------------- # This function paints a bunch of lines radially around # where R1 and R2 are the inner and outer radii and Segments # indicates the number of lines. #-------------------------------------------------------------- def addStarburst (Canvas,Xc,Yc,R1,R2,Segments): return #-------------------------------------------------------------- # This function paints ONE anime eyeball on the Canvas, # centered at . The color of the iris is NewColor, the # pupil is black, and the highlights are white. The sizes and # positions of the iris, pupil, and highlights are derived # from center point and the radius of the iris R. #-------------------------------------------------------------- def addEyeball (Canvas,Xc,Yc,R,NewColor): return #-------------------------------------------------------------- # This function paints a Greeble on the Canvas at center # with Xradius indicating the size of the Greeble # (everything else is computed from those three values). # The Greeble has ellipses for the body and mouth, and calls # addEyeball TWICE (once for each eye). #-------------------------------------------------------------- def addGreeble (Canvas,Xc,Yc,Xradius,NewColor): return #-------------------------------------------------------------- # This function computed the optimal X radius for the Greeble # based on the size of the Canvas, then plots the Greeble at # the center of the screen with that X radius. #-------------------------------------------------------------- def Stare (Canvas,NewColor): return #-------------------------------------------------------------- # Prompt the user for a color. You MAY NOT change ANY code # in the requestColor function! #-------------------------------------------------------------- def requestColor (Message): while True: S = requestString(Message) S = S.lower() if (S == "red"): return red if (S == "green"): return green if (S == "blue"): return blue if (S == "cyan"): return cyan if (S == "magenta"): return magenta if (S == "yellow"): return yellow #-------------------------------------------------------------- # This function establishes the size of the canvas and the # color of the eyes. You MAY NOT change ANY code in # the Main function! #-------------------------------------------------------------- def Main (): W = requestIntegerInRange("Enter Width", 100, 1000) H = requestIntegerInRange("Enter Height", 100, 1000) C = requestColor("Enter a Color") Canvas = makeEmptyPicture(W,H,makeColor(240)) Stare(Canvas,C) show(Canvas) return #-------------------------------------------------------------- # Test programs to exercise the various functions as they are # being developed. #-------------------------------------------------------------- def TestEllipse (): Canvas = makeEmptyPicture(400,400) addEllipse(Canvas,getWidth(Canvas)/2,getHeight(Canvas)/2,150,50,blue) show(Canvas) return def TestEllipseFilled (): Canvas = makeEmptyPicture(400,400) addEllipseFilled(Canvas,getWidth(Canvas)/2,getHeight(Canvas)/2,150,50,blue) show(Canvas) return def TestCircleFilled (): Canvas = makeEmptyPicture(400,400) addCircleFilled(Canvas,getWidth(Canvas)/2,getHeight(Canvas)/2,150,blue) show(Canvas) return def TestStarburst (): Canvas = makeEmptyPicture(400,400) addStarburst(Canvas,getWidth(Canvas)/2,getHeight(Canvas)/2,150,100,40) show(Canvas) return def TestEyeball (): Canvas = makeEmptyPicture(400,400) addEyeball(Canvas,getWidth(Canvas)/2,getHeight(Canvas)/2,150,blue) show(Canvas) return