Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom PShape: if used with add_child() doesn't render #329

Open
adigiosaffatte opened this issue Oct 29, 2021 · 1 comment
Open

Custom PShape: if used with add_child() doesn't render #329

adigiosaffatte opened this issue Oct 29, 2021 · 1 comment

Comments

@adigiosaffatte
Copy link

adigiosaffatte commented Oct 29, 2021

I tried to run the following code:

from p5 import *

star = None

def setup():
    global star
    size(3000, 1200)
    star = PShape()
    rect_shp = rect(300,300,100,100)
    star.add_child(rect_shp)

def draw():
    global star
    background(125)
    draw_shape(star)

I'm expecting to see a rectangle on my screen but I can't see anything.
I found that function draw_shape(shape, pos=(0, 0, 0)) defined in primitives.py (line 791) begins with the following statement:

p5.renderer.render(shape)

and only AFTER handles the children:

for child_shape in shape.children:
    draw_shape(child_shape)

I think this behaviour is incorrect, the function should check the presence of children before calling p5.renderer.render(shape).
In fact, I tried to modify the function in this way:

def draw_shape(shape, pos=(0, 0, 0)):
    if isinstance(shape, Geometry):
        return
    
    elif not len(shape.children):
        p5.renderer.render(shape)

    else:
        for child_shape in shape.children:
            draw_shape(child_shape)

and it worked: I was able to render my rectangle!

What do you think?
Am I using the custom PShape in the wrong manner or it is actually a bug?

Thank you!

@github-actions
Copy link
Contributor

Thank you for submitting your first issue to p5py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant