Browse Source

Shapes have independent rythym

main
Luke Murphy 4 years ago
parent
commit
45d5cad7db
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 26
      voicegardens/static/voicegardens.js

26
voicegardens/static/voicegardens.js

@ -276,6 +276,12 @@ class GeneratedShape {
this.deltaX = this.destX - this.centerX - toScreenX;
this.deltaY = this.destY - this.centerY - toScreenY;
// time management for timing when to make new random position
// movements
this.drawTimer = 0;
this.nextTick = random(1000, 9000);
this.tickTimer = 0;
this.initialise();
}
@ -397,6 +403,21 @@ class GeneratedShape {
endShape(CLOSE);
}
tick() {
/**
* Manage internal time for each shape.
**/
this.drawTimer = millis();
if (this.drawTimer >= this.nextTick + this.tickTimer) {
this.tickTimer = millis();
this.nextTick = random(1000, 9000);
return true;
}
return false;
}
draw() {
/**
* Draw the shape vectors.
@ -507,6 +528,11 @@ function draw() {
shape.draw();
shape.move();
if (shape.tick() === true) {
shape.destX = random(windowWidth);
shape.destY = random(windowHeight);
}
// play recordings when shapes collide
let [collision, collidedShape] = shape.collide(shapes);
if (collision === true) {

Loading…
Cancel
Save