Skip to content

Formula

Formula(body, materials=None, font=None, math_font=None, **attrs)

Bases: Formula

# Two placeholders
# minus signed is named minus
# plus sign will be named + by default
latex = r"a     erm[minus]- \ph[target] = b + \ph[source]"
frm = Formula(latex)

c = Formula("c")

plus  = frm.by_name("+")
minus = frm.by_name("minus")

# Placeholrders 
tgt = frm.by_name("target")
tgt.formula = c

src = frm.by_name("source")
src.formula = c

# Target placeholder
frm.update()
tr1 = tgt.absolute_transfo

# Starting from no minus sign and no target placeholder
tgt.anim.sx = 0.0
minus.anim.sx = 0.0

# The source placeholder
frm.update()
tr0 = src.absolute_transfo

# Animation
def update():

    factor = np.clip((engine.frame-50)/100, 0, 1)

    tgt.anim.sx     = factor
    src.anim.sx     = 1 - factor
    minus.anim.sx   = factor
    plus.anim.sx    = 1 - factor

    c.move_to(tr0, tr1, factor, ymax=1.0, turns=0, smooth='SMOOTH')

    # The two formulas to objects
    frm.to_mesh().to_object("Formula")           
    c.to_mesh().to_object("c")

engine.go(update)

get_bbox

get_bbox()

Formula bbox is the body bbox plus decorators

get_body_bbox

get_body_bbox()

Surrounding BBox for all the formulas in terms list.

x_align

x_align(x, align='left', margin=0.0)

Update the transformation to align the bbox horizontally.

Note : the margin is multiplied by the animation scale

Parameters:

Name Type Description Default
x float

Position to align the bbox to

required
align str in (left, center, right)

alignment mode default is 'left'

'left'
margin float

additional margin default is 0.0

0.0

Returns:

Type Description
self

y_align

y_align(y, align='bottom', margin=0.0)

Update the transformation to align the bbox vertically.

Note : the margin is multiplied by the animation scale

Parameters:

Name Type Description Default
x float

Position to align the bbox to

required
align str in (bottom, middle, top)

alignment mode default is 'bottom'

'bottom'
margin float

additional margin default is 0.0

0.0

Returns:

Type Description
self