Simple python class wont render Invoking <bound method Sketch.on_timer of Sketch> (p5py)

I’m trying to make a simple class.


class class_circle:
    def __init__(self, r):
        self.r = r

    def show(self):
        fill(255)
        circle(0,0,self.r)


c = class_circle(100)

def setup():
    size(1280, 720)

def draw():
    background(0)
    c.show()

run()

but i get the error

ERROR: Invoking <bound method Sketch.on_timer of <Sketch (Glfw) at 0x7f0e8d6757d0>> for Event

not sure what happened, I tried finding another example online and I got the same error. Would very much appreciate your help :smiley:

Hi,

Is there the same error with a simple program (without any class, only with setup and draw)?

What is the function run() ?

thanks for helping me out josephh.
The function run is from p5. I guess it calls setup and then runs the draw loop. nothing happens without the run command.

Brilliant suggestion for fixing the error. I thought I’ve checked everything but I forgot the position should be a vector.

So in the show() method this fixed my error:
circle(0,0,self.r) --> circle((0,0),self.r)

So this is the full working class:

class class_circle:
    def __init__(self, r):
        self.r = r

    def show(self):
        fill(255)
        circle((0,0),self.r)
1 Like

I just realised that your code is working fine on my machine using Processing.py

Reading the documentation for the circle() function, the first two parameters are the x and y location, it’s not a tuple : https://py.processing.org/reference/circle.html

You are using Processing.py right? It seems that there is no need for a run() function, it’s not in the reference or in any tutorials :

For p5, you must use a tuple for your x-y coordinates:

circle((0, 0), self.r)

ty @josephh. I’m usig p5py. As I understood proccesing.py is only python2.7 doesn’t let me import whatever python package I want in my own editor.

@tabreturn ty. If I ever learn how to contribute to a package I would love to make pyp5 return an error code like “First index should be tuple, not scalar”

1 Like

@villares is actually looking at possibly creating API wrapper or fork to address these kinds of mismatches. See: API compatibility for p5py

1 Like

Than you for this solution @jeremydouglass. I’m new to devloping python packages. Why not add these helpful error message in the main package? To me it seems helpful - but I would love to know what an experienced developer thinks

It would be helpful, I agree! The only reason I can think of not to would be if the extra error handling incurred a performance hit – or if the method could be made smarter by handling non-tuple arguments correctly in line with the other APIs, in which case that error message would no longer make sense.

There is currently a proposal to do that here:

edit

But you could also open a PR with proposed error messages instead / in the meantime / as well.

I see - Thank you :slight_smile: