Skip to content

Updating in a for or while loop #49

Open
@kushalkolar

Description

@kushalkolar

Finally catching up with all this! Taking a look at the examples and wondering if this would be the right way to update the canvas in a for or while loop. It works but I'm not sure if this is the way it's intended to be used, without an event loop running.

import numpy as np
from rendercanvas.auto import RenderCanvas, loop

canvas = RenderCanvas(update_mode="ondemand")
context = canvas.get_context("bitmap")

for i in range(100):
    w, h = canvas.get_logical_size()
    shape = int(h) // 4, int(w) // 4

    bitmap = np.random.uniform(0, 255, shape).astype(np.uint8)
    context.set_bitmap(bitmap)
    canvas.force_draw()

related: pygfx/pygfx#667

I'm starting to think about how to implement this for fastplotlib, might help to have a mode where the canvas is updated only when an event occurs or when any buffer in the scene changes? Anyways that will be a separate issue which I'll think about later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions