I'm trying to make a voice recorder visualizer where the shapes would interact with little squares that are being passed from the left to the right of the screen to make it seem like it's recording a voice note. For some reason, I cannot get the squares to space exactly how I want them to, so I decided to push one square out at a time and when that square reaches a certain part on the screen, another square would start from the beginning so they can move at the speed and have the distance between each other I would like.
The problem is when I get the square to reach a certain part on the screen, the other square does not add at all, I tried adding a fill to change the color to see what happens but it just changes the color of the current square and that's it.
var nodes;
function setup() {
createCanvas(windowWidth, windowHeight)
nodes = new Particle();
}
function draw() {
background(0);
if (!nodes.deleteParticles()) {
nodes.draw();
nodes.update()
}
}
function Particle() {
this.x = windowWidth / 2;
this.y = windowHeight / 2;
this.width = 20;
this.height = 50;
this.particles = [];
this.draw = function() {
background(0)
fill(255);
this.particles.push(rect(this.x, this.y, this.width, this.height, 5))
if (this.update()) {
this.particles.push(rect(this.x, this.y, this.width, this.height, 5))
}
}
this.update = function() {
this.x -= 2;
if (this.x < (windowWidth / 2) - 300) {
return true;
} else {
return false;
}
}
this.deleteParticles = function() {
if (this.x < -20) {
return true;
} else {
return false;
}
}
}
<!DOCTYPE html>
<html>
<head>
<script src="lib/p5.min.js"></script>
<script src="lib/p5.sound.js"></script>
<script src="sketch.js"></script>
<!--<link rel="stylesheet" type="text/css" href="style.css">-->
<style>
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
</body>
</html>