3.1. Displaying and saving canvases

Once a sketch has been drawn on a canvas, it can be used for several goals:

  • Displaying the canvas in the screen.
  • Producing an image out of it and save it to a file, raster or vectorial.
  • Including it as a figure in some report created by Anableps, too.
  • Perform some calculations or simulations on it. Scope of simulations is wide: heat transmission, electromagnetism, kinematics, among others
  • Make some animation of the shapes, either by following laws of kinematics, or moving them in some other way.
  • Convert to another format.

This chapter is about the two first actions:

3.1.1. Displaying on the screen

Displaying a given canvas in the screen is pretty easy:

canvas1.display: .width 400

this opens a window 400px width, in which the contents of the canvas are shown. There are several parameters that activate controls

3.1.1.1. Options for the display command

  • .width : specifies the width of the canvas in the screen
  • .height: specifies the height of the canvas in the screen
  • .controls: displays controls (save button, etc)

For the full set of options of the ‘’display’’ command, see canvas reference

3.1.2. Saving a canvas into a file

Saving it to a file goes along the same lines:

canvas.save: .filename myfile.png .width 400px

The command save saves the contents of a canvas in a file, using some file format.

3.1.2.1. Options

  • .filename: the name of the file. If this name contains an extension and no .format given, format will be deduced from this value
  • .format: the for this image. See here the available formats and their options.
  • .width: sets the width in pixels for the image. Height will be modified accordingly with the current aspect
  • .height: sets the height in pixels for the image. Width will be modified accordingly with the current aspect
  • .size: sets both the width and the height.

For the full set of options of the ‘’display’’ command, see canvas reference

3.1.3. The 2D rendering pipeline

The rendering process is actually more complicated. We’ve just seen the default way. In brief, first, all the shapes are told to drawn themselves in the current canvas. Shapes draw themselves by issuing drawing primitives (lines, points, arcs, text…).

3.1.3.1. Postprocessors

Those primitives are saved in a final canvas and a vectorial shader is called, who can modify, add or delete them. If the final format is vectorial, a formatter is called that transforms the primitives into the desired code.

For raster ouputs, however, the canvas is rasterized and then a pixel shader called, that can perform additional operations on pixels.

A full explanation of the 2d rendering pipeline is be given in the section 3.10