Skip to main content

Align To

Description

The align_to function is used for two main purposes:

  • to align a mobject's edge E to edge E of another mobject where E is the direction parameter.
  • to move a mobject so that its corner C is positioned at the corner C of another mobject, where C is the direction parameter.

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 in direction.

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 1

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)
Example 2