We are about to switch to a new forum software. Until then we have removed the registration on this forum.
sketch.js:
var number_of_explosions = 10;
var explosionarray = [];
var mycollision = false;
function setup(){
for (var i = 0; i < number_of_explosions; i++) {
explosionarray[i] = new explosion();
console.log(explosionarray.length)
}
}
function draw(){
createCanvas(400,400);
background(155);
for (var i = 0; i < explosionarray.length; i++) {
mycollision = collision(explosionarray[i].position.x,explosionarray[i].position.y,25);
if (mycollision){
explosionarray[i].isdestroyed(true)
}
if (explosionarray[i].destroyed == false){
explosionarray[i].display();
}
}
}
function collision(xpos,ypos,radius){
var distance = dist(xpos,ypos,mouseX,mouseY);
if (distance <= radius){
return true;
}
else{
return false;
}
}
explosion.js:
function explosion(){
this.w = 50;
this.h = 50;
this.destroyed = false;
this.position = createVector(random(25,375), random(25,375));
this.display = function(){
fill(100);
ellipse(this.position.x, this.position.y, this.w, this.h);
}
this.isdestroyed = function(dbool){
if (dbool){
this.destroyed = true;
}
else{
this.destroyed = false;
}
}
}
Hi all. Any help would be greatly appreciated.
This code basically draws circles on the screen and tracks the collision between the mouse and the circle. When the mouse has collided with the circle it is no longer drawn.
What I want to do though is not draw all the circles at once but with a delay between them. e.g. draw an 'explosion' track the collision and after a random amount of time has passed say between 1 to 3 seconds it draws the second one and then tracks both the first and second collisions.
I was thinking about using the time functions for p5 but cant get my head around when it switches from 59 back to 0!
Say on one cycle i have var take_time = second() this is then stored and compared to the random number. But if I scan at 58 and the random number is 3 I am looking for the take_time to now be 1! I know this must be possible but my little brain is struggling. Cheers!
Answers
http://Bl.ocks.org/GoSubRoutine/1a0d21828319cf18fecf44101764bd60
https://Forum.Processing.org/two/discussion/23846/time-delay-in-python-mode#Item_16
@sampazzer Don't use seconds() - that's more useful if you're building a clock ;)
Instead use millis():
my emphasis above. Store a start time in a variable and then check when current millis() hits the desired value; do something and reset the startTime variable... You'll find examples in the forum if you search