I want to create a music visualizer, and to do this I want to build an array which safes instructions in order of occurrence in the music. I then want to build a function that parses through the array at a set speed and performs the instructions.
So for example I have an array with {a,b,a,b,a} and for every a the screen turns red for every b the screen turns black.
I tried using Threads and the sleep() function but it wouldn't wake up again. I'm frankly at a loss as to what to do next.
You could use the modulo operator along with the frameCount variable to do something every X frames.
Here's a little example that changes the background every 60 frames, or once per second:
void draw() {
if (frameCount % 60 == 0) {
background(random(255), random(255), random(255));
}
}
This uses hard-coded 60 to change the background once per second, but you could get that number from an array instead.
来源:https://stackoverflow.com/questions/38144038/timing-based-events-in-processing