begin_record()

Opens a new file and all subsequent drawing functions are echoed to this file as well as the display window.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def setup():
    py5.size(400, 400)
    py5.begin_record(py5.PDF, "everything.pdf")


def draw():
    py5.ellipse(py5.mouse_x, py5.mouse_y, 10, 10)


def mouse_pressed():
    py5.end_record()
    py5.exit_sketch()
1
2
3
4
5
6
7
8
9
def setup():
    py5.size(200, 200)

    with py5.begin_record(py5.SVG, "/tmp/test.svg") as r:
        py5.rect_mode(py5.CENTER)
        r.fill("#F00")  # affects the recorded output only

        for _ in range(10):
            py5.square(py5.random(py5.width), py5.random(py5.height), 10)

Description

Opens a new file and all subsequent drawing functions are echoed to this file as well as the display window. The begin_record() function requires two parameters, the first is the renderer and the second is the file name. This function is always used with end_record() to stop the recording process and close the file.

Note that begin_record() will only pick up any settings that happen after it has been called. For instance, if you call text_font() before begin_record(), then that font will not be set for the file that you’re recording to.

begin_record() works only with the PDF and SVG renderers.

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

Underlying Java method: beginRecord

Syntax

begin_record(recorder: Py5Graphics, /) -> None
begin_record(renderer: str, filename: str, /) -> Py5Graphics

Parameters

  • filename: str - filename for output

  • recorder: Py5Graphics - Py5Graphics object to record drawing commands to

  • renderer: str - PDF or SVG

Updated on September 25, 2021 10:36:03am UTC