FPS drops on drawing sprites using custom images

I just wrote a very short program to learn something about custom images and found out that the FPS drops drastically. I know what I’ve done can be done without the image but this is just a experiment. Here’s the code

function setup()
    Y=HEIGHT/2
    parameter.number("FPS",0,60,60)
end

function draw()
    background(0, 0, 0, 255)
    Y = Y + 1
    img=image(WIDTH,HEIGHT)
    setContext(img)
        pushStyle()
        fill(255, 0, 0, 255)
        ellipse(WIDTH/2,Y,40)
        popStyle()
    setContext()
    sprite(img,WIDTH/2,HEIGHT/2)
    FPS = .9*FPS+.1/DeltaTime
end

The reason is probably that you’re redrawing the image from scratch, 60 times a second.

The best way to use a custom image is to draw it once, eg in setup, then sprite that image in draw.

If you’re going to create it in draw, you might as well just draw it straight to the screen and forget about the custom image

Thanks @Ignatz worked out by creating the image in the setup and just changing how the image looks in the draw function.