Transformations
In [1]:
Copied!
from chalk.core import BaseDiagram
from chalk import *
def help(f):
import pydoc
from IPython.display import HTML
return HTML(pydoc.HTMLDoc().docroutine(f))
from chalk.core import BaseDiagram from chalk import * def help(f): import pydoc from IPython.display import HTML return HTML(pydoc.HTMLDoc().docroutine(f))
Any Diagram (or other object in Chalk) can be transformed by affine transfomation. These produce a new diagram in the standard manner.
scale¶
In [2]:
Copied!
help(BaseDiagram.scale)
help(BaseDiagram.scale)
Out[2]:
- scale(self: ~TTrans, α: float) -> ~TTrans
In [3]:
Copied!
triangle(1) | triangle(1).scale(2)
triangle(1) | triangle(1).scale(2)
Out[3]:
Transformations apply to the whole diagram.
In [4]:
Copied!
(triangle(1) | triangle(1)).scale(2)
(triangle(1) | triangle(1)).scale(2)
Out[4]:
translate¶
In [5]:
Copied!
help(BaseDiagram.translate)
help(BaseDiagram.translate)
Out[5]:
- translate(self: ~TTrans, dx: float, dy: float) -> ~TTrans
In [6]:
Copied!
triangle(1).translate(1, 1).show_envelope().show_origin()
triangle(1).translate(1, 1).show_envelope().show_origin()
Out[6]:
In [7]:
Copied!
triangle(1) + triangle(1).translate(1, 1)
triangle(1) + triangle(1).translate(1, 1)
Out[7]:
shear_x¶
In [8]:
Copied!
help(BaseDiagram.shear_x)
help(BaseDiagram.shear_x)
Out[8]:
- shear_x(self: ~TTrans, λ: float) -> ~TTrans
In [9]:
Copied!
square(1).shear_x(0.25).show_envelope()
square(1).shear_x(0.25).show_envelope()
Out[9]:
In [10]:
Copied!
square(1) | square(1).shear_x(0.25)
square(1) | square(1).shear_x(0.25)
Out[10]:
rotate¶
In [11]:
Copied!
help(BaseDiagram.rotate)
help(BaseDiagram.rotate)
Out[11]:
- rotate(self: ~TTrans, θ: float) -> ~TTrans
- Rotate by θ degrees counterclockwise
In [12]:
Copied!
triangle(1) | triangle(1).rotate(90)
triangle(1) | triangle(1).rotate(90)
Out[12]:
rotate_by¶
In [13]:
Copied!
help(BaseDiagram.rotate_by)
help(BaseDiagram.rotate_by)
Out[13]:
- rotate_by(self: ~TTrans, turns: float) -> ~TTrans
- Rotate by fractions of a circle (turn).
In [14]:
Copied!
triangle(1) | triangle(1).rotate_by(0.2)
triangle(1) | triangle(1).rotate_by(0.2)
Out[14]:
Last update: 2022-08-19