Next / Previous / Contents / Shipman's homepage

10. Xscale(): Create a scaling transform

Creates a scaling transform. If the argument is a single number, that scale factor is applied to both coordinates; if it a sequence, it must be a sequence of two numbers, one to be applied to each coordinate. For the logic that decodes the positional arguments, see Section 15, “argPair(): Process one or two arguments”.

homcoord.py
# - - -   X s c a l e

def Xscale(*p):
    '''Create a scaling transform.
    '''
    #-- 1 --
    # [ if p is a single value or single-valued iterable ->
    #     sx  :=  that value
    #     sy  :=  that value
    #   else ->
    #     sx  :=  the first value from p
    #     sy  :=  the second value from p ]
    sx, sy = argPair ( *p )

    #-- 2 --
    # [ return an Xform for scaling x by sx and scaling y by sy ]
    return Xform ( [ (sx, 0,  0),
                     (0,  sy, 0),
                     (0,  0,  1) ] )