Skip to main content

Beaver Studio

An open-source 2D graphics engine for video generation, particularly for educational purposes.

WIP: Beaver Studio is still under heavy development and does not yet have a stable API!

Requirements

MSRV (Minimum Supported Rust Version): 1.81.0

Usage

Beaver Studio has three important data structures. The first is the Video data structure, which holds information about animations and renders them on screen. The second is the Animation data structure, which holds information about animations of 2D geometry. The third is the Shape data structure, which holds information about 2D geometries, such as polygons and Bezier curves.

The typical workflow begins with the creation of one or more Shape structures. After creating these shapes, they can be converted into Animation structures using interpolations, traces, or simple display. These animations can then be scheduled in the video and rendered on screen.

To begin, import Beaver Studio.

from beaverstudio import *

Creating a Video Object

All animations are rendered in videos, which are modeled by a sequence of still frames. To initialize a video, specify the width and height, background color (RGB), frame rate, and duration (in seconds).

video = Video(
    (1920, 1080),   # width, height (pixels)
    [0, 0, 0],      # background color (RGB)
    60,             # frame rate (fps)
    10,             # duration (seconds)
)

Creating Points

In Beaver Studio, the center of the video frame is considered the origin. All points can be constructed relative to this origin by the Vector class. Distances are specified in pixels relative to this origin.

p1 = Vector(-10, 10)

Creating Geometry

Nearly all geometry is animated by means of Shape objects. Shapes can be constructed manually, or by creating polygons or curves and converting them.

Building Bezier Curves

Bezier curves may be created using the Bezier class. To create a Bezier curve, specify two or more control points of the curve (in Vector form), an offset to apply to all control points, a color, and a thickness.

b1 = Bezier(
    [point1, point2, point3],   # control points
    Vector.zero(),              # offset
    [255, 0, 0],                # color (RGB)
    2,                          # line thickness (pixels)
)

Bezier curves can be converted into Shape objects by the .shape attribute.

s1 = b1.shape

Manually Constructing Shapes

Shapes can be manually constructed using a series of Bezier curves. To create a Shape manually, specify a list of Bezier curves and an offset.

s2 = Shape(
    [bezier1, bezier2], # Bezier curves
    Vector.zero(),      # offset
)

Building Rectangles

Rectangles can be creating using the Rect class. To create a Rect, specify a center, width, height, color, and line thickness.

r1 = Rect(
    Vector.zero(),  # center
    100,            # width (pixels)
    200,            # height (pixels)
    [0, 255, 255],  # color (RGB)
    10,             # line thickness (pixels)
)

Rectangles can be converted into Shape objects by the .shape attribute.

s3 = r1.shape

Building Closed Polygons

Closed polygons can be created using the Polygon class. To create a Polygon, specify a list of vertices (in Vector form), an offset, a color, and a line thickness.

poly1 = Polygon(
    [vertex1, vertex2, vertex3, vertex4],   # vertices
    Vector.zero(),                          # offset
    [255, 0, 255],                          # color
    12,                                     # line thickness (pixels)
)

Polygons can be converted into Shape objects by the .shape attribute.

s4 = poly1.shape

Building Coordinate Axes

Coordinate axes do not use the Shape class. Currently, only linear-linear axes are supported. To create linear axes, specify an origin location, a grid spacing, and minor gridline counts left and right of the Y axis and above and below the X axis, respectively.

axes = LinearAxes(
    Vector.zero(),  # origin location (pixels)
    100,            # grid spacing
    (8, 8),         # minor gridlines left and right of Y axis
    (5, 5),         # minor gridlines above and below X axis
)

Coordinate axes can be traced, displayed, and untraced directly.

axes_anim = axes.trace

Building Parametric Curves

Parametric curves, like coordinate axes, do not use the Shape class. To create a parametric curve, specify two functions of time for the X and Y positions, as well as time bounds, an offset, a color, and a thickness. Note that the result of the X and Y positions are in pixels. If using this with coordinate axes, ensure that this is consistent with the axes' grid spacing, for best results.

para1 = Parametric(
    lambda t: 100*t,            # X position
    lambda t: 100*sin(100*t),   # Y position
    (-3.14, 3.14),              # time bounds (min, max)
    Vector.zero(),              # offset (pixels)
    [255, 0, 0],                # color (RGB)
    4,                          # line thickness (pixels)
)

Creating Animations

Once Shape objects have been created, they need to be converted into Animation objects before they can be added to the video.

Interpolation

One shape can smoothly become another using the Shape.into() method.

anim1 = shape1.into(shape2)

Display

A shape can be simply displayed using the .display attribute.

anim2 = shape.display

Trace

You can trace out a shape, creating a real-time drawing effect, by the .trace attribute.

anim3 = shape.trace

You can also "untrace" the shape, creating a real-time erasing effect, by the .untrace attribute.

anim4 = shape.untrace

Adding Animations to the Video

Animations are added to the video using Video.add(). To add an animation, specify its offset, its start time (in seconds), and its end time (in seconds).

video.add(
    animation,      # animation
    Vector.zero(),  # offset
    1.5,            # start time (seconds)
    3,              # end time (seconds)
)

Metadata

Release files for beaverstudio 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for beaverstudio 0.1.0
File Size Uploaded Provenance
beaverstudio-0.1.0.tar.gz 25.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for beaverstudio 0.1.0
File Interpreter ABI Platform
beaverstudio-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details

Total release size: 2.0 MB

Release files / beaverstudio-0.1.0.tar.gz

Download URL beaverstudio-0.1.0.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2c1b3ebdb3ae2aced84130acfebc36611e65cf610d363b223cfe7020901d5da4
BLAKE2b-256 checksum
How to use checksums
c217fbffa38aee7b921be97e0a72032eb52ba3a9ae59b31bb418c7744ade7c28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.2

Release files / beaverstudio-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL beaverstudio-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 1.9 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
0570d2d1b8f1025da06bcf66a60058942465ec6d5841cdd47314a14188a36ff6
BLAKE2b-256 checksum
How to use checksums
16ff1db50c8b6b148873a533c3fbac32954cf4caf70ee542dcfb8f37a52adbe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.2

Security for beaverstudio 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page