pythagoras.r3.canvas module

class pythagoras.r3.canvas.Canvas3D(dimensions: tuple[float, float], origin: tuple[float, float] = (0, 0), camera: Camera3D | None = None, frustum: float = 1, scale: float = 1)[source]

Bases: PObject

Container for a collection of PObject3D’s. Controls the SVG and TikZ output for the entire 3D scene.

Variables:
  • dimensions (tuple[float, float]) – Width and height of the canvas.

  • origin (tuple[float, float]) – Point in 2D space to which the origin of the frame of reference corresponds.

  • camera (pythagoras.r3.camera.Camera3D) – Camera3D object encoding the position and pointing direction of the rendering camera.

  • frustum (float) – Field of view within the scene.

  • scale (float) – The scaling factor by which the canvas is stretched.

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

Appends a 3D object together with its properties into the list of elements to be renderded.

Parameters:
  • objPObject3D 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_light_source(position: tuple[float, float, float], intensity: float) None[source]

Includes a light source into the scene. By default, the camera emmits light with an intensity equal to the frustum; this behavior may be changed through the camera_as_light_source() property.

Parameters:
  • position – Position of the light source.

  • intensity – Its brightness.

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

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

Parameters:
  • objs – Sequence of PObject3D’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.

camera: Camera3D
property camera_as_light_source: bool

Returns True if the camera is acting as a light source, False otherwise.

dimensions: tuple[float, float]
extrema() list[tuple[float, float]][source]

Computes the furthermost points of the figure.

Returns:

A list with the bounding points of the object.

frustum: float
origin: tuple[float, float]
scale: float
svg(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into SVG commands.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The corresponding SVG code.

tikz(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into a sequence of TikZ instructions.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The resulting TikZ code.