Primitive shapes and text

Functions to create primitive graphics (shapes and text)

circular_sector(radius: float, angle: float, color: Color) Graphic

Creates a circular sector belonging to a circle of the given radius, filled with a color.

A circular sector is a portion of a circle enclosed between two radii and an arc. Considering a circle as a clock, the first radius is supposed to “point” towards 3 o’clock. The angle determines the position of the second radius, computed starting from the first one in the clockwise direction.

Parameters:
  • radius – radius of the circle from which the circular sector is taken, in pixel

  • angle – central angle, in degrees

  • color – the color to be used to fill the circular sector

Returns:

the specified circular sector as a graphic

ellipse(width: float, height: float, color: Color) Graphic

Creates an ellipse with the given width and height, filled with a color.

When width and height are the same, the ellipse becomes a circle with a diameter equal to the provided size.

Parameters:
  • width – width of the ellipse, in pixel

  • height – height of the ellipse, in pixel

  • color – the color to be used to fill the circle

Returns:

the specified circle as a graphic

empty_graphic() Graphic

Creates an empty graphic. When an empty graphic is composed with any other graphic, it behaves as a neutral element: the result is always identical to the other graphic.

An empty graphic cannot be shown nor saved.

Returns:

an empty graphic (width and height 0 pixels)

rectangle(width: float, height: float, color: Color) Graphic

Creates a rectangle of the given size, filled with a color.

Parameters:
  • width – width of the rectangle, in pixel

  • height – height of the rectangle, in pixel

  • color – the color to be used to fill the rectangle

Returns:

the specified rectangle as a graphic

text(content: str, font: str, points: float, color: Color) Graphic

Creates a graphic with the text rendered using the specified font, size and color.

When the indicated True-Type Font is not found in the system, a very basilar font that is always available is used instead. The resulting graphic has the minimal size that still fits the whole text.

Parameters:
  • content – the text to render

  • font – the name of the font (e.g., “arial” on Windows, “Arial” on macOS)

  • points – size in typographic points (e.g., 16)

  • color – the color to be used to render the text

Returns:

the specified text as a graphic

triangle(side: float, color: Color) Graphic

Creates an equilateral triangle pointing upwards of the given side, filled with a color.

Parameters:
  • side – length of the side of the triangle, in pixel

  • color – the color to be used to fill the triangle

Returns:

the specified triangle as a graphic