Skip to content

API reference

Create — a creative coding library for rapid prototyping and interactive graphics.

from create import * is the import a program needs. It brings in the whole public surface: the Program trait and the run loops, Context, keyboard, mouse and gamepad input, Canvas and the rendering types, the vector and matrix maths, the shapes and curves, images, fonts, audio, CSV tables and JSON, the circle constants PI and TAU, and a re-export of std.math so sin and cos are there without a second import.

from create import *


@fieldwise_init
struct Sketch(Program):
    var angle: Float64

    @staticmethod
    def create(mut context: Context, mut canvas: Canvas) raises -> Self:
        return Self(0.0)

    def update(mut self, mut context: Context, mut canvas: Canvas) raises:
        self.angle += context.time.delta
        canvas.background(Color.BLACK)
        canvas.circle((100 * cos(self.angle), 100 * sin(self.angle)), 20)


def main() raises:
    run[Sketch]("Sketch", width=1280, height=720)

The subpackages stay importable on their own — from create.render import * gives the rendering stack with no run loop, which is what run_headless is built on — so this module is a convenience, not a layer.

What this module re-exports is the union of the subpackages. Each of them exports the names it owns and nothing from a layer below — create.core names Canvas and Rectangle in its signatures but exports neither — so a single subpackage star is never a preamble; this module is. It re-exports everything public by star-importing all ten, so a name added to math/__init__.mojo appears here with no second edit and the two cannot drift apart.

Code that wants less than the whole surface imports by name from the package that defines it (from create.geometry import overlaps), rather than starring one subpackage.

The stars widen nothing on their own. A star import skips _-prefixed declarations and reaches only what a package's __init__.mojo lists, so _raster's blend, _bytes's le_uint and text/font.mojo's _GlyphInfo stay internal here exactly as they are one level down.

create.core

The run: the Program trait, run and run_headless, the run's state (Context, Time) and its settings (WindowMode, Cursor), text entry (EditableText), source_path and DateTime.

Context, Time, DateTime, source_path, Program, WindowMode, Cursor, run, run_headless, EditableText

create.input

The input devices Context holds: Keyboard, Mouse and Gamepad, and the Key, MouseButton and GamepadButton they are read with.

Keyboard, Key, Mouse, MouseButton, Gamepad, GamepadButton

create.math

Maths: Point2D, Vector2D and Matrix, Random and Noise, easing and Tween, scalar helpers, PI and TAU, and the common std.math functions.

lerp, map, inverse_lerp, smoothstep, sign, fractional_part, wrap, degrees, radians, Easing, ease, Tween, Point2D, Vector2D, Matrix, identity, inverse, apply, translate, rotate, scale, Random, Noise, PI, TAU

create.geometry

Shapes and curves, the traits that make a type drawable, and the collision tests: overlaps, and each shape's contains and intersects.

Rectangle, Circle, Ellipse, Capsule, Line, Triangle, Arc, Sector, Polygon, overlaps, Bezier, Spline, Curve, Drawable, DrawTarget, Region, Shape

create.color

Colours: Color, Gradient and BlendMode.

Color, Gradient, BlendMode

create.render

Drawing: Canvas and its with-block guards, Style, Camera, and the settings that shape a frame (Antialiasing, Autoscale, Align, StrokeCap, StrokeDash, StrokeAlign, RenderBackend).

RenderBackend, Antialiasing, Align, StrokeAlign, StrokeCap, StrokeDash, Autoscale, Style, Camera, Canvas, StyleGuard, TransformGuard, OverlayGuard, ClipGuard

create.image

Images and animation: Image, PixelBuffer, Animation and Animator.

Image, PixelBuffer, Animation, Animator

create.text

Fonts: Font and FontWeight, with Noto Sans built in.

Font, FontWeight

create.audio

Sound: Sound (the asset), Audio (the playback device) and Voice (one playback).

Sound, Audio, Voice

create.data

Data files: Table and TableRow for CSV and TSV, and JSON.

Table, TableRow, JSON, JSONKind