Glimmr Canvas-Based Drawing

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Define the canvas

    Defining the canvas is also quite easy. We simply declare the canvas object and associate it with a g-window:

        The graphics-canvas is a g-canvas. The associated canvas of the graphics-window is the graphics-canvas.
        
    We should also specify the dimensions of the canvas. There are two ways to do this. We can set the width and height directly:

        The canvas-width of the graphics-canvas is 600. The canvas-height of the graphics-canvas is 300.
        
    Or we can supply a background image for the canvas. The background image will be drawn underneath (that is, before) any of the elements associated with the canvas are drawn. If we have not explicitly set the canvas dimensions as described above, the background image will itself define the dimensions of the canvas. We declare the background image like this:

        The background image of the graphics-canvas is Figure of Background.
        
    Again, the background image will only define the canvas dimensions for us if we have not specified dimensions, or if we have specified either the width or the height at 0. If, on the other hand, we have specified dimensions in advance, the background image will be resized to fit the previously defined dimensions. It will even be stretched to fit if need be.