In section~#secmovecircle#7045>, we developed functions for drawing,
translating, and clearing circles and rectangles. As we have just seen, we
should think of the two classes of data as subclasses of a class of general
shapes so that we can just draw, translate, and clear shapes.
<#7048#>Exercise 7.4.1<#7048#>
Provide a data definition for a general class of <#7050#>shape<#7050#>s. The class
should at least subsume the classes of colored circles and rectangles from
section~#secmovecircle#7051>.
Develop the template <#61623#><#7052#>fun-for-shape<#7052#><#61623#>, which outlines functions that
consume <#61624#><#7053#>shape<#7053#><#61624#>s.~ Solution<#61625#><#61625#>
<#7059#>Exercise 7.4.2<#7059#>
Use the template <#61626#><#7061#>fun-for-shape<#7061#><#61626#> to develop <#61627#><#7062#>draw-shape<#7062#><#61627#>.
The function consumes a <#61628#><#7063#>shape<#7063#><#61628#> and draws it on the
canvas.~ Solution<#61629#><#61629#>
<#7069#>Exercise 7.4.3<#7069#>
Use the template <#61630#><#7071#>fun-for-shape<#7071#><#61630#> to develop
<#61631#><#7072#>translate-shape<#7072#><#61631#>. The function consumes a <#61632#><#7073#>shape<#7073#><#61632#> and a number
<#61633#><#7074#>delta<#7074#><#61633#>, and produces a shape whose key position is moved by
<#61634#><#7075#>delta<#7075#><#61634#> pixels in the x-direction.~ Solution<#61635#><#61635#>
<#7081#>Exercise 7.4.4<#7081#>
Use the template <#61636#><#7083#>fun-for-shape<#7083#><#61636#> to develop <#61637#><#7084#>clear-shape<#7084#><#61637#>.
The function consumes a <#61638#><#7085#>shape<#7085#><#61638#>, erases it from the canvas, and returns
<#61639#><#7086#>true<#7086#><#61639#>.~ Solution<#61640#><#61640#>
<#7092#>Exercise 7.4.5<#7092#>
Develop <#61641#><#7094#>move-shape<#7094#><#61641#>, which moves a shape across the canvas. The function
consumes a number (<#61642#><#7095#>delta<#7095#><#61642#>) and a <#61643#><#7096#>shape<#7096#><#61643#> and moves it by
<#61644#><#7097#>delta<#7097#><#61644#> pixels on a canvas. The function should wait for one second
between clearing and drawing the new rectangle.~ Solution<#61645#><#61645#>