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:
PObjectContainer 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) –
Camera3Dobject 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:
obj –
PObject3Dto be included into the scene.*args – Parameters of the object, i.e.:
Fill(BLUE)orStroke(RED). Seepythagoras.stylefor 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)orStroke(RED). Seepythagoras.stylefor further information on styling.
- property camera_as_light_source: bool¶
Returns
Trueif the camera is acting as a light source,Falseotherwise.
- 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
Canvasinstance.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
Canvasinstance.args – Properties of the object.
- Returns:
The resulting TikZ code.