Align To
Description
The align_to function is used for two main purposes:
- to align a mobject's edge
Eto edgeEof another mobject whereEis thedirectionparameter. - to move a mobject so that its corner
Cis positioned at the cornerCof another mobject, whereCis thedirectionparameter.
Parameters
point_or_mobject(Point3D | Mobject): The point or mobject to align to.direction(Vector3, default=UP): Represents either the main axis (an edge:UP,DOWN,LEFT,RIGHT) or both the main and secondary axes (a corner:UR,UL,DR,DL) to align this mobject to the target.buff(float, default=0): The buffer distance to apply after alignment. Applied along whatever axes are present indirection.
Examples
Example 1
A stretched circle aligned to the top edge of a rectangle, with a tiny buff.
from smanim import *
rect = Rectangle(width=1, height=2, color=GRAY)
circle = Circle(radius=0.5, color=DARK_GRAY, z_index=2)
circle.stretch(1.5, dim=0)
circle.align_to(rect, UP, buff=TINY_BUFF)
canvas.add(rect, circle)
canvas.draw(crop=True, ignore_bg=True)
Example 2
A small square aligned to be in the corner of larger rectangle.
from smanim import *
rect = Rectangle(color=GRAY, opacity=0.5)
square = Square(side_length=0.5, color=YELLOW, opacity=0.5)
square.align_to(rect, UL)
canvas.add(rect, square)
canvas.draw(crop=True, ignore_bg=True)