Extended Exercise: Moving Pictures, a Last Time

In sections~#secmovecircle#56918>, #secmoveshape#56919>, #secmovefig#56920>, and~#secabsmoving#56921> we studied how to move pictures across a canvas. A picture is a list of shapes; a shape is one of several basic geometric shapes: circles, rectangles, etc. Following our most basic design principle---one function per concept---we first defined functions for moving basic geometric shapes, then for mixed classes of shapes, and finally for lists of shapes. Eventually we abstracted over related functions. The functions for moving basic shapes create a new shape from an existing shape. For example, the function for moving a circle consumes a <#69980#><#56922#>circle<#56922#><#69980#> structure and produces a new <#69981#><#56923#>circle<#56923#><#69981#> structure. If we think of the <#69982#><#56924#>circle<#56924#><#69982#> as a painting with a round frame and the canvas as a wall, however, creating a new shape for each move is inappropriate. Instead, we should change the shape's current position.
<#56927#>Exercise 41.4.1<#56927#> Adapt the functions <#69983#><#56929#>translate-circle<#56929#><#69983#> and <#69984#><#56930#>translate-rectangle<#56930#><#69984#> of exercises~#excircdraw#56931> and~#exrectdraw#56932>, respectively, so that they mutate their inputs instead of creating new geometric shapes. Adapt <#69985#><#56933#>move-circle<#56933#><#69985#>, defined in section~#secmovecircle#56934>, and <#69986#><#56935#>move-rectangle<#56935#><#69986#> from exercise~#exrectmove#56936> so that they use these new functions.~ external Solution<#69987#><#69987#> <#56942#>Exercise 41.4.2<#56942#> Adapt the function <#69988#><#56944#>move-picture<#56944#><#69988#> from exercise~#exmoving#56945> to use the structure-mutating functions from exercise~#exmupicture1#56946>. <#56947#>Hint:<#56947#> \ Timing effects is critical in this exercise.~ external Solution<#69989#><#69989#> <#56953#>Exercise 41.4.3<#56953#> Use Scheme's <#69990#><#56955#>for-each<#56955#><#69990#> function to abstract where possible in the functions of exercise~#exmupicture2#56956>.~ external Solution<#69991#><#69991#>