Attributes

Module: vectormation.attributes

All VObject properties (positions, sizes, colours) are time-varying attributes. Instead of holding a single value, each attribute stores a function of time and can be animated with move_to, set_onward, set, etc.


Real

class Real(creation, start_val=0)

Time-varying float. The fundamental attribute type.

Parameters:
  • creation (float) – Creation time.

  • start_val (float) – Initial value.

time_func: callable

Internal function f(t) -> float.

last_change: float

Time of the most recent modification.

Reading

at_time(time)

Get the value at time.

Returns:

float

Setting Values

set_onward(start, value)

Set a constant or callable from start onward. If value is callable, it receives t and should return a float.

r.set_onward(0, 5.0)               # constant
r.set_onward(0, lambda t: t * 2)    # function of time
add_onward(start, func)

Add a constant or callable to the current value from start onward.

set(start, end, func_inner, stay=False)

Override with a custom function on [start, end]. If stay=True, the end value persists after end.

Parameters:

func_inner (callable) – f(t) -> float

add(start, end, func_inner, stay=False)

Add a function’s output on [start, end].

set_at(time, value)

Set value at a single point in time.

set_to(other)

Copy another Real’s time function.

Animation

move_to(start, end, end_val, stay=True, easing=smooth)

Animate from current value to end_val over [start, end].

circle.r.move_to(0, 2, 3.0)  # radius grows to 3 over 2 seconds
interpolate(other, start, end, easing=linear)

Create a new Real that interpolates between self and other.


Coor

class Coor(creation, start_val=(0, 0))

Bases: Real

Time-varying 2D coordinate (x, y). Inherits all Real methods.

Parameters:

start_val (tuple) – Initial (x, y) position.

at_time(time)
Returns:

(float, float)

move_to(start, end, end_val, stay=True, easing=smooth)

Animate position to end_val.

Parameters:

end_val (tuple) – Target (x, y).

dot.c.move_to(0, 2, (12, 3))  # move to (12, 3) over 2 seconds
rotate_around(start, end, pivot_point, degrees, clockwise=False, stay=True)

Rotate around a pivot point over [start, end].

Parameters:
  • pivot_point(x, y) tuple or Coor.

  • degrees (float) – Rotation angle (counterclockwise by default).

  • clockwise (bool) – Reverse direction.

dot.c.rotate_around(0, 2, (960, 540), 360)  # full orbit
along_path(start, end, path_d, easing=smooth, stay=True)

Move along an SVG path string over [start, end].

Parameters:

path_d (str) – SVG path data.


Color

class Color(creation=0, start_color='#000', use=None)

Time-varying colour. Supports hex strings ('#ff0000'), RGB tuples ((255, 0, 0)), RGBA tuples, named colours, and gradients.

at_time(time)
Returns:

SVG colour string (e.g. 'rgb(255,0,0)')

set_onward(start, value)

Set colour from start onward. Accepts hex, RGB tuple, or callable.

interpolate(other, start, end, easing=linear, color_space='rgb')

Interpolate to another colour.

Parameters:

color_space (str) – 'rgb' or 'hsl'.

interpolate_hsl(other, start, end, easing=linear)

Interpolate through HSL colour space (smoother for hue transitions).


String

class String(creation, start_val='')

Time-varying string attribute. Same interface as Real.


Tup

class Tup(creation, start_val=())

Bases: Real

Time-varying tuple. Used internally for rotation (degrees, cx, cy) and matrix transforms. Interpolation is element-wise.