Timing based events in Processing

2019-01-20 19:31发布

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.

1条回答
We Are One
2楼-- · 2019-01-20 20:12

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.

查看更多
登录 后发表回答