Scripton / Docs

Rendering

Canvas.draw_image

Renders the given image onto the canvas.

  • You can optionally specify a position (x, y, by default both 0) for the top-left corner, as well as a target size (width, height, by default equal to the input image's size).

  • An opacity value may also be specified for the composition.

Acceptable types for the input image include:

  • A PIL image instance
  • A uint8 NumPy array representing an RGB (h, w, 3) or RGBA (h, w, 4) image.
from scripton.canvas import Canvas from PIL import Image canvas = Canvas(width=640, height=480) canvas.draw_image( image=Image.open('overlay.png'), opacity=0.5 )

Canvas.from_image

Creates a canvas instance containing the given image.

This is equivalent to creating a canvas with width and height matching the image and then calling draw_image.

from scripton.canvas import Canvas from PIL import Image canvas = Canvas.from_image(Image.open('background.png'))

Canvas.draw_matrix

Renders a colormapped version of the given matrix (either a NumPy array or a PyTorch tensor) onto the canvas.

  • The optional target bounds (x, y, width, height) and opacity behave as described in draw_image

  • The optional colormap keyword argument can be set to one of the values displayed in the IDE.

  • The optional range keyword argument can specify the (min, max) ranges corresponding to the extremes of the colormap. By default, the matrix's min/max values are used.

  • If you just want to display a colormapped version of the matrix with no further changes, consider using the simpler show function.

from scripton.canvas import Canvas import numpy as np x = np.arange(100) matrix = np.abs(x[:, None] - x) canvas = Canvas(width=640, height=480) canvas.draw_matrix( matrix, colormap='Magma', x=270, y=190, )

Canvas.from_matrix

Creates a canvas instance containing a colormapped version of the given matrix.

This is equivalent to creating a canvas with width and height matching the matrix and then calling draw_matrix.

from scripton.canvas import Canvas import numpy as np x = np.arange(100) matrix = np.abs(x[:, None] - x) canvas = Canvas.from_matrix(matrix)