Graphical Window Sprites

version 1 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Part 2 - Backgrounds and Scaling

    Grid-background is a truth state that varies. Grid-background is usually false. The grid-x is a number that varies. The grid-y is a number that varies. Grid-x is 0. Grid-y is 0.

    The window x-scaling factor is a real number that varies. The window y-scaling factor is a real number that varies. The window-scaling factor is a real number that varies. The window-scaling factor is 1.0000.

    The window x-offset is a number that varies. The window y-offset is a number that varies.

    Background-width is a number that varies. Background-height is a number that varies.

    To determine the scaling and offset factors:
        let x-win be current graphics window width [defined by Simple Graphical Window] as a fixed point number;
        let y-win be current graphics window height [defined by Simple Graphical Window] as a fixed point number;
        if grid-background is false:
            change grid-x to the image-width of the currently shown picture;
            change grid-y to the image-height of the currently shown picture;
        let x-bkgd be grid-x;
        let y-bkgd be grid-y;
        if x-bkgd < 1:
            say "***Debug msg: No background defined.";
            rule fails;
        change the window x-scaling factor to x-win real divided by x-bkgd;
        change the window y-scaling factor to y-win real divided by y-bkgd;
        if the window x-scaling factor is real greater than the window y-scaling factor:
            change the window-scaling factor to the window y-scaling factor;
        otherwise:
            change the window-scaling factor to the window x-scaling factor;
        change background-width to the window-scaling factor real times the x-bkgd as an integer;
        change background-height to the window-scaling factor real times the y-bkgd as an integer;
        change window x-offset to the current graphics window width minus background-width divided by 2;
        change window y-offset to the current graphics window height minus background-height divided by 2.

    To determine the offset factor:
        if grid-background is false:
            change grid-x to the image-width of the currently shown picture;
            change grid-y to the image-height of the currently shown picture;
        change background-width to grid-x;
        change background-height to grid-y;
        if background-width < 1:
            say "***Debug msg: No background defined.";
            rule fails;
        change window x-offset to the current graphics window width minus background-width divided by 2;
        change window y-offset to the current graphics window height minus background-height divided by 2.
        
    To decide which real number is (N - a number) scaled by (R - a real number):
        Let temp be N as a fixed point number;
        let temp be temp real times R;
        decide on temp.
        
    To decide which real number is (N - a real number) scaled by (R - a real number):
        Let temp be N real times R;
        decide on temp.

    To decide what number is the image-width of (img - a figure-name):
        (- FindImageWidth({img}); -)
        
    To decide what number is the image-height of (img - a figure-name):
        (- FindImageHeight({img}); -)