Combinators
In [1]:
Copied!
import math
from planar import Vec2
from chalk import *
def help(f):
import pydoc
from IPython.display import HTML
return HTML(pydoc.HTMLDoc().docroutine(f))
import math from planar import Vec2 from chalk import * def help(f): import pydoc from IPython.display import HTML return HTML(pydoc.HTMLDoc().docroutine(f))
Complex diagrams can be created by combining simpler diagrams through placement combinators. These place diagrams above, atop or besides other diagrams. Relative location is determined by the envelope and origins of the diagrams.
beside¶
In [2]:
Copied!
help(beside)
help(beside)
Out[2]:
- beside(self: chalk.types.Diagram, other: chalk.types.Diagram, direction: planar.vector.Vec2) -> chalk.types.Diagram
In [3]:
Copied!
diagram = triangle(1).beside(square(1), unit_x)
diagram
diagram = triangle(1).beside(square(1), unit_x) diagram
Out[3]:
In [4]:
Copied!
triangle(1).show_beside(square(1), unit_x)
triangle(1).show_beside(square(1), unit_x)
Out[4]:
In [5]:
Copied!
triangle(1).show_beside(triangle(1).rotate_by(1 / 6), Vec2.polar(-45))
triangle(1).show_beside(triangle(1).rotate_by(1 / 6), Vec2.polar(-45))
Out[5]:
In [6]:
Copied!
triangle(1).show_beside(triangle(1).rotate_by(1 / 6), Vec2.polar(-30))
triangle(1).show_beside(triangle(1).rotate_by(1 / 6), Vec2.polar(-30))
Out[6]:
above¶
In [7]:
Copied!
help(above)
help(above)
Out[7]:
- above(self: chalk.types.Diagram, other: chalk.types.Diagram) -> chalk.types.Diagram
In [8]:
Copied!
diagram = triangle(1) / square(1)
diagram
diagram = triangle(1) / square(1) diagram
Out[8]:
In [9]:
Copied!
diagram.show_envelope().show_origin()
diagram.show_envelope().show_origin()
Out[9]:
atop¶
In [10]:
Copied!
help(atop)
help(atop)
Out[10]:
- atop(self: chalk.types.Diagram, other: chalk.types.Diagram) -> chalk.types.Diagram
Example 1 - Atop at origin
In [11]:
Copied!
diagram = square(1) + triangle(1)
diagram
diagram = square(1) + triangle(1) diagram
Out[11]:
In [12]:
Copied!
diagram.show_envelope().show_origin()
diagram.show_envelope().show_origin()
Out[12]:
Example 2 - Align then atop origin
In [13]:
Copied!
s = square(1).align_r().align_b().show_origin()
t = triangle(1).align_l().align_t().show_origin()
s
s = square(1).align_r().align_b().show_origin() t = triangle(1).align_l().align_t().show_origin() s
Out[13]:
In [14]:
Copied!
t
t
Out[14]:
In [15]:
Copied!
s + t
s + t
Out[15]:
In [ ]:
Copied!
vcat¶
In [16]:
Copied!
help(vcat)
help(vcat)
Out[16]:
- vcat(diagrams: Iterable[chalk.types.Diagram], sep: Optional[float] = None) -> chalk.types.Diagram
- Stack diagrams above each other with `above`.
Args:
diagrams (Iterable[Diagram]): Diagrams to stack.
sep (Optional[float]): Padding between diagrams.
Returns:
Diagrams
In [17]:
Copied!
vcat([triangle(1), square(1), triangle(1)], 0.2)
vcat([triangle(1), square(1), triangle(1)], 0.2)
Out[17]:
concat¶
In [18]:
Copied!
help(concat)
help(concat)
Out[18]:
- concat(diagrams: Iterable[chalk.types.Diagram]) -> chalk.types.Diagram
- Concat diagrams atop of each other with atop.
Args:
diagrams (Iterable[Diagram]): Diagrams to concat.
Returns:
Diagram: New diagram
In [19]:
Copied!
concat([triangle(1), square(1), triangle(1)])
concat([triangle(1), square(1), triangle(1)])
Out[19]:
hcat¶
In [20]:
Copied!
help(hcat)
help(hcat)
Out[20]:
- hcat(diagrams: Iterable[chalk.types.Diagram], sep: Optional[float] = None) -> chalk.types.Diagram
- Stack diagrams next to each other with `besides`.
Args:
diagrams (Iterable[Diagram]): Diagrams to stack.
sep (Optional[float]): Padding between diagrams.
Returns:
Diagram: New diagram
In [21]:
Copied!
hcat([triangle(1), square(1), triangle(1)], 0.2)
hcat([triangle(1), square(1), triangle(1)], 0.2)
Out[21]:
place_on_path¶
In [22]:
Copied!
help(place_on_path)
help(place_on_path)
Out[22]:
- place_on_path(diagrams: Iterable[chalk.types.Diagram], path: chalk.shapes.path.Path) -> chalk.types.Diagram
In [23]:
Copied!
place_on_path(
[circle(0.25) for _ in range(6)],
Trail.regular_polygon(6, 1).to_path(),
)
place_on_path( [circle(0.25) for _ in range(6)], Trail.regular_polygon(6, 1).to_path(), )
Out[23]:
Last update: 2022-10-11