xxxxxxxxxx
48
// https://discourse.processing.org/t/make-different-objects-appear-at-different-timing/9806
// https://www.w3schools.com/js/js_timing.asp
// TEST setTimeout(function, millis) or setInterval(function, millis)
let donow = false;
let dt = 3000;
let rr;
let ang = 0;
function setup() {
createCanvas(400, 400);
print("set timer " + dt);
setTimeout(start, dt);
rectMode(CENTER);
fill(200, 0, 0); //for timeshow
}
function draw() {
background(200, 200, 0);
noStroke();
text(nf(millis() / 1000, 1, 1), 10, 20);
translate(width / 2, height / 2);
ang += 0.01;
rotate(ang);
if (donow) draw_rect();
}
function start() {
print("start");
donow = true;
rr = 200;
}
function draw_rect() {
stroke(0, 200, 0);
strokeWeight(10);
fill(0, 200, 200);
rect(0, 0, rr, rr);
rr--;
fill(0, 0, 200); // for timeshow while timer NOT running
if (rr < 3) {
donow = false;
setTimeout(start, dt);
print("restart timer " + dt);
fill(200, 0, 0); // for timeshow while timer running
//ang = 0;
}
}