Download Editing Graphical Objects Using Procedural
Transcript
I· yield any picture yet. The focus of editing shifts to the definition of car so any new objects added will be added to this definition, (function main (meehod ) Figure 4-13: Example: the initial program (function main (method (wieh (eranalaee [325 25]) (objeoe a oar (oar») (draw a_oar) - (defineobjeoe oar (meehod ) Figure 4-14: Example: instantiating a car In a step not shown here, the user specifies the default fill pattern to be 50% gray and the default line width to be zero. He then uses Add twice to create two instantiations of the library object filled_rectangle. Filled_rectangle takes three arguments, a point, a number named %linewidth, and a paint named %fillpaint, and draws and fills a rectangle from the point (0,0) to the passed point with a border width of %linewidth and a fill pattern of %fillpaint. Because the number and paint parameters are named %linewidth and %fillpaint, Dee automatically supplies their values. Figure 4-15 shows the result of adding these two rectangles. For each, Dee requests the value for the origin and then the value for the point parameter using the mouse. In the first rectangle, body, the origin is at the origin of the car, so there is need for a with statement to translate it. In the second, top, the origin is at the point (25,30), so a with statement is required. (defineobject car (method (objeoe body (filled reoeangle [100 30] 0 (g~ay.oal. 0.5») (draw body) (wieh (eranalaee [25 30]) (objeoe eop (filled reaeangle [50 25] 0 (grayaaale 0.5»» (draw eop) Figure 4-15: Example: adding the car body •