I use python mode and Processing 3.5.4.
I would like to use the setup function to draw background elements once before animating in the draw function. However, have an issue when I choose the P2D or P3D renderer.
def setup(): size(400,400) ellipse(200,200,30,30) def draw(): rect(100,100,20,20)
In this case, the circle is drawn once in the setup function, and then the rectangle in the draw loop. However, if I change rendering modes by using: size(400,400,P2D) or P3D, the circle is overdrawn and disappears.
How can I avoid that if I want to draw something just once, out of the drawing loop? Is drawing in setup a bad practice?
To circumvent that problem, I tried to use a method I found in a tutorial, using loadPixels but it doesn’t work either.
background_image = None def setup(): size(400,400,P2D) global background_image background_image= createImage(400,400,RGB) ellipse(200,200,30,30) loadPixels() background_image.loadPixels() background_image.pixels = pixels background_image.updatePixels() def draw(): background(background_image) rect(100,100,20,20)
What am I doing wrong?