-
If I set the 4 def setup():
(...)
10
11 canvas_width = 500
12 canvas_height = int(canvas_width * 1.41421)
13
--> 14 py5.size(canvas_width, canvas_height)
15
..................................................
canvas_width = 500
canvas_height = 707
..................................................
RuntimeError: Cannot call the size() method here. Either move it to a settings() function or move it to closer to the start of setup(). But how I am supposed to set a canvas size? In the Processing example they do set the example code import py5
def setup():
global canvas_width
global canvas_height
global pg1
global pg2
global pg3
canvas_width = 500
canvas_height = int(canvas_width * 1.41421)
py5.size(canvas_width, canvas_height)
pg1 = py5.create_graphics(canvas_width, int(canvas_height / 3))
pg2 = py5.create_graphics(canvas_width, int(canvas_height / 3))
pg3 = py5.create_graphics(canvas_width, int(canvas_height / 3))
def draw():
pg1.begin_draw()
pg1.background("#00ff00")
pg1.end_draw()
pg2.begin_draw()
pg2.background(0)
pg2.fill("#ff00ff")
pg2.circle(0, 0, 100)
pg2.end_draw()
pg3.begin_draw()
pg3.background("#0000ff")
pg3.rect(0, 0, 200, 200)
pg3.end_draw()
py5.image(pg1, 0, 0)
py5.image(pg2, 0, canvas_height)
py5.image(pg3, 0, canvas_height * 2)
py5.run_sketch() And if I set the render to 4 def setup():
(...)
12 canvas_height = int(canvas_width * 1.41421)
13
14 # py5.size(canvas_width, canvas_height)
15
--> 16 pg1 = py5.create_graphics(canvas_width, int(canvas_height / 3), py5.P2D)
17 pg2 = py5.create_graphics(canvas_width, int(canvas_height / 3), py5.P2D)
..................................................
canvas_width = 500
canvas_height = 707
py5.P2D = 'processing.opengl.PGraphics2D'
..................................................
java.lang.RuntimeException: java.lang.RuntimeException: createGraphics() with P2D requires size() to use P2D or P3D |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @kresdjan ! Thanks for giving py5 a try. Can you move the call to canvas_width = 500
canvas_height = int(canvas_width * 1.41421)
def setup():
global pg1, pg2, pg3
py5.size(canvas_width, canvas_height)
pg1 = py5.create_graphics(canvas_width, int(canvas_height / 3))
pg2 = py5.create_graphics(canvas_width, int(canvas_height / 3))
pg3 = py5.create_graphics(canvas_width, int(canvas_height / 3)) py5, like Processing, requires you to call I see you wanted to define the two def setup():
global pg1, pg2, pg3
py5.size(500, int(500 * 1.41421))
pg1 = py5.create_graphics(py5.width, int(py5.height / 3))
pg2 = py5.create_graphics(py5.width, int(py5.height / 3))
pg3 = py5.create_graphics(py5.width, int(py5.height / 3))
def draw():
pg1.begin_draw()
pg1.background("#00ff00")
pg1.end_draw()
pg2.begin_draw()
pg2.background(0)
pg2.fill("#ff00ff")
pg2.circle(0, 0, 100)
pg2.end_draw()
pg3.begin_draw()
pg3.background("#0000ff")
pg3.rect(0, 0, 200, 200)
pg3.end_draw()
py5.image(pg1, 0, 0)
py5.image(pg2, 0, py5.height)
py5.image(pg3, 0, py5.height * 2) I also see you did get a bit tripped up by this page: http://py5coding.org/reference/py5graphics.html In py5, like Processing, there is in implicit call to |
Beta Was this translation helpful? Give feedback.
Hi @kresdjan ! Thanks for giving py5 a try.
Can you move the call to
py5.size()
to the beginning of thesetup()
function? You can have it after the global statements and comments but not after anything else. Like this:py5, like Processing, requires you to call
size()
at the beginning ofsetup()
. The reason for this is that both py5 and Processin…