Timed and independant movements
This commit is contained in:
parent
9f20ecc0ef
commit
b62a028443
@ -20,7 +20,8 @@ var shapes = [];
|
|||||||
var stopButton;
|
var stopButton;
|
||||||
var canvasWidth;
|
var canvasWidth;
|
||||||
var canvasHeight;
|
var canvasHeight;
|
||||||
var timer;
|
var timer = 0;
|
||||||
|
var secondTick = false;
|
||||||
|
|
||||||
function record() {
|
function record() {
|
||||||
/**
|
/**
|
||||||
@ -170,6 +171,9 @@ class GeneratedShape {
|
|||||||
this.destX = random(canvasWidth);
|
this.destX = random(canvasWidth);
|
||||||
this.destY = random(canvasHeight);
|
this.destY = random(canvasHeight);
|
||||||
|
|
||||||
|
this.centerX = centerX;
|
||||||
|
this.centerY = centerY;
|
||||||
|
|
||||||
this.initialise();
|
this.initialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,9 +247,13 @@ class GeneratedShape {
|
|||||||
|
|
||||||
for (let i = 0; i < this.edges; i++) {
|
for (let i = 0; i < this.edges; i++) {
|
||||||
this.startXs[i] =
|
this.startXs[i] =
|
||||||
centerX + cos(radians(this.rotAngle) * i) * this.radius + this.randomX;
|
this.centerX +
|
||||||
|
cos(radians(this.rotAngle) * i) * this.radius +
|
||||||
|
this.randomX;
|
||||||
this.startYs[i] =
|
this.startYs[i] =
|
||||||
centerY + sin(radians(this.rotAngle) * i) * this.radius + this.randomY;
|
this.centerY +
|
||||||
|
sin(radians(this.rotAngle) * i) * this.radius +
|
||||||
|
this.randomY;
|
||||||
this.rotAngle += 360 / this.edges;
|
this.rotAngle += 360 / this.edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,8 +269,8 @@ class GeneratedShape {
|
|||||||
/**
|
/**
|
||||||
* Move the shape vectors.
|
* Move the shape vectors.
|
||||||
**/
|
**/
|
||||||
this.deltaX = this.destX - centerX;
|
this.deltaX = this.destX - this.centerX;
|
||||||
this.deltaY = this.destY - centerY;
|
this.deltaY = this.destY - this.centerY;
|
||||||
|
|
||||||
this.deltaX *= this.springing;
|
this.deltaX *= this.springing;
|
||||||
this.deltaY *= this.springing;
|
this.deltaY *= this.springing;
|
||||||
@ -270,8 +278,8 @@ class GeneratedShape {
|
|||||||
this.accelX += this.deltaX;
|
this.accelX += this.deltaX;
|
||||||
this.accelY += this.deltaY;
|
this.accelY += this.deltaY;
|
||||||
|
|
||||||
centerX += this.accelX;
|
this.centerX += this.accelX;
|
||||||
centerY += this.accelY;
|
this.centerY += this.accelY;
|
||||||
|
|
||||||
this.accelX *= this.damping;
|
this.accelX *= this.damping;
|
||||||
this.accelY *= this.damping;
|
this.accelY *= this.damping;
|
||||||
@ -318,11 +326,16 @@ function draw() {
|
|||||||
newSoundJustRecorded = false;
|
newSoundJustRecorded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (millis() >= 2000 + timer) {
|
||||||
|
secondTick = true;
|
||||||
|
timer = millis();
|
||||||
|
}
|
||||||
|
|
||||||
for (var shape of shapes) {
|
for (var shape of shapes) {
|
||||||
shape.draw();
|
shape.draw();
|
||||||
shape.move();
|
shape.move();
|
||||||
|
|
||||||
if (millis() >= 500 + timer) {
|
if (secondTick) {
|
||||||
shape.destX = random(canvasWidth);
|
shape.destX = random(canvasWidth);
|
||||||
shape.destY = random(canvasHeight);
|
shape.destY = random(canvasHeight);
|
||||||
}
|
}
|
||||||
@ -331,6 +344,5 @@ function draw() {
|
|||||||
shape.sound();
|
shape.sound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
secondTick = false;
|
||||||
timer = millis();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user