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

Unable to run custom setup and draw #471

Closed
martynvdijke opened this issue Apr 25, 2024 · 3 comments
Closed

Unable to run custom setup and draw #471

martynvdijke opened this issue Apr 25, 2024 · 3 comments

Comments

@martynvdijke
Copy link

martynvdijke commented Apr 25, 2024

Describe the bug
I want to trigger my own function for setup and drawing.
however this does not seem to work as my code below crashed at
File ".venv/lib/python3.11/site-packages/p5/sketch/userspace.py", line 260, in size p5.sketch.size = (builtins.width, builtins.height) AttributeError: 'NoneType' object has no attribute 'size'
It seems that on this size() there is no sketch attribute to p5, but I have tried digging into but cant seem to understand why that is the case ?

To Reproduce

import p5

def setup():
   p5.size(128,64)
   p5.no_loop()
   p5.fill(0)

def draw():
   p5.background(204)
   p5.text("LAX", (0, 40))
   p5.text("LHR", (0, 70))
   p5.text("TXL", (0, 100))
   
p5.run(sketch_setup=setup(),sketch_draw=draw())

Expected behavior
To be able to draw using custom defined function.

System information:

  • p5 release (version number or latest commit):
  • Python version: 3.11
  • Operating system: Arch Linux
Copy link
Contributor

Thank you for submitting your first issue to p5py

@tushar5526
Copy link
Member

tushar5526 commented Apr 26, 2024

Hi @martynvdijke, it should be

p5.run(sketch_setup=setup,sketch_draw=draw)

You don't have to call the function while passing it. You can also use p5py like this

from p5 import *


def setup():
    size(128, 64)
    no_loop()
    fill(0)


def draw():
    background(204)
    text("LAX", (0, 40))
    text("LHR", (0, 70))
    text("TXL", (0, 100))

# experimental but better 2D renderer
run(renderer='skia')

@martynvdijke
Copy link
Author

Thank you that works !

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

2 participants