setTimeout - the image is not fixed on the screen (p5.js)

0

Programming in javascript / p5.js

I'm trying to use the setTimeout function, but the image, when fired, flashes on the screen, not fixed. The idea is that the ellipse appears after a certain time, and remains. First I thought it was a bug in my code, so I cleaned everything up until it was just the setTimeout function and still exhibited the same behavior. Is this a p5.js problem or what?

function setup() {
createCanvas(windowWidth, windowHeight);    
}

function draw(){

background(25);

function ball(){
stroke(255);
noFill();
ellipse(200, 200, 50, 50);
}

setTimeout(ball, 2000);

}

Thank you.

    
asked by anonymous 18.08.2018 / 11:18

2 answers

1

You could try this:

function setup() {
createCanvas(windowWidth, windowHeight);
}

var reload = false;

function draw() {

background(25);

function ball() {
    stroke(255);
    noFill();
    ellipse(200, 200, 50, 50);
    reload = true;
}

if (!reload) {
    setTimeout(ball, 2000);
}

}
    
18.08.2018 / 16:53
0

From what Heathcliff said, I found this solution: setTimeout trigger true, and within an if == true condition, draw the ellipse

var ball = false;

function setup() {
createCanvas(windowWidth, windowHeight);
}

function draw() {
background(25);

setTimeout(delay, 3000);

function delay(){
ball = true;
}

if (ball)
{
fill(255);
ellipse(200, 200, 50, 50);
}
}

Thank you!

    
21.08.2018 / 13:06