Go to the first, previous, next, last section, table of contents.

Controlling the scaling of a picture

By default, the Picture a glyph displays is scaled to fit whatever size is currently allocated for it. In many cases, this automatic scaling is fine, but there are cases where you want to have control over what gets displayed at different sizes, e.g., suppose you have a Picture of some fractal landscape (god forbid!) and when the glyph is doubled in size, you want to include a larger area of the landscape rather than scaling up the area you already have. This level of control over what should be displayed at different sizes is supported by the clumsily named type ResizeablePicture:


type ResizeablePicture = Size -> Picture

i.e., a function that given a particular Glyph size returns the Picture to display at that size. As an example, here is a ResizeablePicture that couples the width and height to the RGB colour triple to use as fill colour:


colouredCircle :: ResizeablePicture
colouredCircle sz@(w,h) =
 withColour (rgb (w,255,h))
            (filledCircle sz)

main =
 mkDC []              >>= \ dc ->
   glyph redCircle dc >>= \ (gl, dh) ->
 realiseDH dc dh      >>
 setResizeablePicture gl colouredCircle >>
 return ()

Green Circle Yellow Circle


Go to the first, previous, next, last section, table of contents.