Transformations¶
-
translate
(x=0, y=0)¶ Translate the canvas with a given offset.
-
rotate
(angle, center=(0, 0))¶ Rotate the canvas around the center point (which is the origin by default) with a given angle in degrees.
-
scale
(x=1, y=None, center=(0, 0))¶ Scale the canvas with a given x (horizontal scale) and y (vertical scale).
If only 1 argument is provided a proportional scale is applied.
The center of scaling can optionally be set via the center keyword argument. By default this is the origin.
-
skew
(angle1, angle2=0, center=(0, 0))¶ Skew the canvas with given angle1 and angle2.
If only one argument is provided a proportional skew is applied.
The center of skewing can optionally be set via the center keyword argument. By default this is the origin.
-
transform
((xx, xy, yx, yy, x, y))¶ Transform the canvas with a transformation matrix.
Managing the Graphics State¶
-
savedState
()¶ Save and restore the current graphics state in a with statement.
# Use the 'with' statement. # This makes any changes you make to the graphics state -- such as # colors and transformations -- temporary, and will be reset to # the previous state at the end of the 'with' block. with savedState(): # set a color fill(1, 0, 0) # do a transformation translate(450, 50) rotate(45) # draw something rect(0, 0, 700, 600) # already returned to the previously saved graphics state # so this will be a black rectangle rect(0, 0, 50, 50)
-
save
()¶ DrawBot strongly recommends to use savedState() in a with statement instead.
Save the current graphics state. This will save the state of the canvas (with all the transformations) but also the state of the colors, strokes…
-
restore
()¶ DrawBot strongly recommends to use savedState() in a with statement instead.
Restore from a previously saved graphics state. This will restore the state of the canvas (with all the transformations) but also the state of colors, strokes…