begin_raw()#

To create vectors from 3D data, use the begin_raw() and end_raw() commands.

Examples#

 1def setup():
 2    py5.size(400, 400, py5.P2D)
 3    py5.begin_raw(py5.PDF, "raw.pdf")
 4
 5
 6def draw():
 7    py5.line(py5.pmouse_x, py5.pmouse_y, py5.mouse_x, py5.mouse_y)
 8
 9
10def key_pressed():
11    if py5.key == ' ':
12        py5.end_raw()
13        py5.exit_sketch()
1def setup():
2    py5.size(400, 400, py5.P2D)
3
4    with py5.begin_raw(py5.PDF, "/tmp/raw.pdf"):
5        py5.rect_mode(py5.CENTER)
6        py5.fill("#F00")
7        for _ in range(10):
8            py5.square(py5.random(py5.width), py5.random(py5.height), 10)

Description#

To create vectors from 3D data, use the begin_raw() and end_raw() commands. These commands will grab the shape data just before it is rendered to the screen. At this stage, your entire scene is nothing but a long list of individual lines and triangles. This means that a shape created with sphere() function will be made up of hundreds of triangles, rather than a single object. Or that a multi-segment line shape (such as a curve) will be rendered as individual segments.

When using begin_raw() and end_raw(), it’s possible to write to either a 2D or 3D renderer. For instance, begin_raw() with the PDF library will write the geometry as flattened triangles and lines, even if recording from the P3D renderer.

If you want a background to show up in your files, use rect(0, 0, width, height) after setting the fill() to the background color. Otherwise the background will not be rendered to the file because the background is not a shape.

This method can be used as a context manager to ensure that end_raw() always gets called, as shown in the last example.

Using hint(ENABLE_DEPTH_SORT) can improve the appearance of 3D geometry drawn to 2D file formats.

Underlying Processing method: beginRaw

Syntax#

begin_raw(raw_graphics: Py5Graphics, /) -> None
begin_raw(renderer: str, filename: str, /) -> Py5Graphics

Parameters#

  • filename: str - filename for output

  • raw_graphics: Py5Graphics - Py5Graphics object to apply draw commands to

  • renderer: str - for example, PDF or DXF

Updated on November 12, 2021 11:30:58am UTC