BrushCue Example: Drift Animation¶
You can use this tool online at https://www.brushcue.com/tools/drift-animation
In [ ]:
!pip install brushcue
In [ ]:
import brushcue as bc
duration = 3.0
@bc.brushcue_fn
def frame(time):
input_image = bc.Composition.monet_women_with_parasol()
drift_x = 180.0
drift_y = 140.0
input_bounds = input_image.bounds()
crop_margin = bc.Float.max(drift_x, drift_y) + 40.0
crop_bounds = bc.Bounds2f.from_x_y_width_height(
input_bounds.min_x() + crop_margin,
input_bounds.min_y() + crop_margin,
input_bounds.width() - (crop_margin * 2.0),
input_bounds.height() - (crop_margin * 2.0),
)
phase = ((time / duration) * bc.Float.pi()) * 2.0
x_offset = drift_x * ((3.0 * phase) + 1.0).sin()
y_offset = drift_y * ((5.0 * phase) + 2.0).sin()
moved = input_image.transform(
bc.Transform2.identity().translation(
bc.Vector2f.from_components(x_offset, y_offset)
)
)
cropped = moved.crop(crop_bounds)
return cropped.transform(
bc.Transform2.identity().translation(
bc.Vector2f.from_components(
-1.0 * crop_bounds.min_x(), -1.0 * crop_bounds.min_y()
)
)
)
graph = bc.Sequence.graph(duration, frame)
ctx = bc.Context()
sequence = graph.execute(ctx)
# Render `sequence` to a video file as needed.