Trails
import math
from chalk import *
from planar import Vec2Array
def help(f):
import pydoc
from IPython.display import HTML
return HTML(pydoc.HTMLDoc().docroutine(f))
Chalk also includes a Trail primitive which allows for creating new Diagrams and more complex shapes. Trails are specified by position-invariant offsets and can be rendered as Paths. See the Koch example for a use case.
Constructors¶
Trails are a sequence of vectors and can be constructed using the from_offsets method:
trail = Trail.from_offsets([V2(1, 0), V2(1, 1), V2(0, 1)])
Converting to Diagram¶
In order to render, Trails have to be turned into Diagrams, which can be achieved using the stroke method.
help(Trail.stroke)
- stroke(self) -> 'Diagram'
trail.stroke()
Transformations¶
Trails can be transformed using the usual geometric transformations, which are also applied to the Diagram object. For example, Trails can be rotated:
help(Trail.rotate_by)
- rotate_by(self: ~TTrans, turns: float) -> ~TTrans
- Rotate by fractions of a circle (turn).
trail2 = trail.rotate_by(0.2)
trail2.stroke()
However, since Trails are translation invariant, applying the translate method leaves the Trail instance unchanged.
Composition¶
Trails form a monoid with addition given by list concatenation and identity given by the empty list. Intuitively, adding two Trails appends the two sequences of offsets.
help(Trail.__add__)
- __add__(self, other: 'Trail') -> 'Trail'
(trail + trail2).stroke()