Scripton / Docs

Overview

scripton.canvas provides a powerful and efficient immediate mode raster graphics API. You can use it for drawing 2D scenes in realtime directly from Python.

The first step is to create a Canvas instance. You can think of it as the image being drawn on.

from scripton.canvas import Canvas canvas = Canvas( width=300, height=200 )
  • The dimensions (width and height) need to be specified at the time of creation. The units are in pixels.

  • The default background color for the canvas is transparent (allowing you to create images with alpha channels). However, you can also specify a background color during creation:

    canvas = Canvas( width=300, height=200, fill='white' )

Once you've created a canvas, you can start drawing using one of the many available primitives. For example:

canvas.draw_circle( x=150, y=100, radius=50, fill='#FAB526' )

Coordinates

The coordinate system for the canvas has its origin (0, 0) at the top left corner, with x increasing to the right and y increasing downwards —

Learn More