BrushCue Example: Spinning Reveal Animation¶

Open In Colab

You can use this tool online at https://www.brushcue.com/tools/spinning-reveal-animation

In [ ]:
!pip install brushcue
In [1]:
import brushcue as bc

duration = 1.3


@bc.brushcue_fn
def frame(time):
    input_image = bc.Composition.monet_women_with_parasol()
    bounds = input_image.bounds()
    rectangle_size = bc.Vector2i.from_components(
        bounds.width().round_to_int(), bounds.height().round_to_int()
    ).to_vector2f()
    rectangle_center = rectangle_size.scalar_multiply(0.5)
    background_color_and_size = bc.Composition.painter(
        bc.Painter.new().add_rectangle_with_render_style(
            bc.Point2f.from_components(rectangle_center.x(), rectangle_center.y()),
            rectangle_size,
            0.0,
            bc.RenderStyle.fill_only(
                bc.Fill.solid(
                    bc.ProfiledColor.from_rgba_srgb(
                        bc.RGBAColor.from_components(0.0, 0.0, 0.0, 1.0)
                    )
                )
            ),
            bc.Transform2.identity().to_list(),
        )
    )
    start_scale = 0.3
    scale = (start_scale + ((time / duration) * (1.0 - start_scale))).pow(2.0)
    bounds_2 = input_image.bounds()
    bounds_3 = input_image.bounds()
    rotations = 2
    bounds_4 = background_color_and_size.bounds()
    bounds_5 = background_color_and_size.bounds()
    return input_image.blend_alpha(
        background_color_and_size,
        bc.Transform2.identity()
        .scale(bc.Vector2f.from_components(scale, scale))
        .translation(
            bc.Vector2f.from_components(
                (
                    (
                        (
                            0.0
                            - bc.Vector2i.from_components(
                                bounds_2.width().round_to_int(),
                                bounds_2.height().round_to_int(),
                            )
                            .x()
                            .to_float()
                        )
                        * scale
                    )
                    / 2.0
                ),
                (
                    (
                        (
                            0.0
                            - bc.Vector2i.from_components(
                                bounds_3.width().round_to_int(),
                                bounds_3.height().round_to_int(),
                            )
                            .y()
                            .to_float()
                        )
                        * scale
                    )
                    / 2.0
                ),
            )
        )
        .rotate(
            ((((time / duration) * bc.Int.to_float(rotations)) * 2.0) * bc.Float.pi())
        )
        .translation(
            bc.Vector2f.from_components(
                (
                    bc.Vector2i.from_components(
                        bounds_4.width().round_to_int(),
                        bounds_4.height().round_to_int(),
                    )
                    .x()
                    .to_float()
                    / 2.0
                ),
                (
                    bc.Vector2i.from_components(
                        bounds_5.width().round_to_int(),
                        bounds_5.height().round_to_int(),
                    )
                    .y()
                    .to_float()
                    / 2.0
                ),
            )
        ),
    )


graph = bc.Sequence.graph(duration, frame)

ctx = bc.Context()
sequence = graph.execute(ctx)
# Render `sequence` to a video file as needed.
[wgpu] using backend Metal — adapter 'Apple M5' (IntegratedGpu), driver ''