Glimmr Canvas-Based Drawing

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - Fitting functions

    [These functions don't also scale the opposite axis; in other words, they scale asymmetrically. To change both height and width, use both phrases in succession.]

    To fit (grid - an image-map) to/into a/-- total/-- width of (X - a number) canvas/-- pixel/pixels/px/units wide/--:
        let image-map-width be a number;
        let width-token be a number;
        if the grid is a tileset image-map:
            let image-map-width be the number of entries in entry 1 of the tile-array of the grid;
            now the tile-width override of the grid is X divided by image-map-width;
            let width-token be the tile-width override of the grid;
        otherwise if the grid is a direct image-map:
            let image-map-width be the number of entries in entry 1 of the tile-array of the grid;
            now the tile-width of the grid is X divided by image-map-width;
            let width-token be the tile-width of the grid;
        otherwise:
            rule fails;
        #if utilizing Glimmr debugging;
         say "[>console][CBD]Trying to fit [grid] to a width of [X] canvas units. Changed tile-width to [width-token]. [if width-token * image-map-width is not X]The width could not be set precisely to [X]. [end if]The overall width before scaling will be [width-token * image-map-width].[<]";
        #end if.
        

    To fit (grid - an image-map) to/into a/-- total/-- height of (Y - a number) canvas/-- pixel/pixels/px/units/-- high/--:
        let height-token be a number;
        let calc-height be a number;
        if the grid is a tileset image-map:
            let the calc-height be the number of entries of the tile-array of the grid;
            now the tile-height override of the grid is Y divided by the calc-height;
            let height-token be the tile-height override of the grid;
        otherwise if the grid is a direct image-map:
            let the calc-height be the number of entries of the figure-array of the grid;
            now the tile-height of the grid is Y divided by the calc-height;
            let height-token be the tile-height of the grid;
        otherwise:
            rule fails;
        #if utilizing Glimmr debugging;
         say "[>console][CBD]Trying to fit [grid] to a height of [Y] canvas units. Changed tile-height override to [height-token]. [if height-token * calc-height is not Y]The height could not be set to [Y]. [end if]The overall height before scaling will be [height-token * calc-height].[<]";
        #end if.