pythagoras.canvas module

class pythagoras.canvas.Canvas(scale: float = 1)[source]

Bases: object

Container class for a collection of PObject’s. Controls the SVG and TikZ output, and resizes automatically when a new element is added.

Variables:

context (pythagoras.pobject.RenderingContext) – State of the canvas; groups its scaling, its bounding box, and so forth. It can be queried to retrieve its current height, origin, etc.

add(obj: PObject, *args: POProperty) None[source]

Appends an element into the list of objects to be renderded.

Parameters:
  • objPObject to be included into the scene.

  • *args – Parameters of the object, i.e.: Fill(BLUE) or Stroke(RED). See pythagoras.style for further information on styling.

add_many(objs: Iterable[PObject], *args: POProperty) None[source]

Appends a collection of elements sharing common arguments into the list of objects to be renderded.

Parameters:
  • objs – Sequence of PObject’s to be included into the scene.

  • *args – Parameters of the object, i.e.: Fill(BLUE) or Stroke(RED). See pythagoras.style for further information on styling.

context: RenderingContext
property scale: float

Scaling factor stored in the context attribute.

svg() str[source]

Render the scene into SVG.

Returns:

The final SVG picture.

tikz() str[source]

Render the scene into TikZ.

Returns:

The compiled TikZ document.