0

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 have to make two threads to be synchronized. You cannot ```notify()``` (wake) others threads that are not synchronized together. –  Jul 01 '16 at 11:18
  • If you are new to SO, see [here](http://stackoverflow.com/help/how-to-ask) how to ask a good question. –  Jul 01 '16 at 11:20
  • @user3348521 would something like [this](http://stackoverflow.com/questions/12417937/create-a-simple-countdown-in-processing/12421641#12421641) help ? – George Profenza Jul 01 '16 at 12:00
  • Did you ever get this figured out? – Kevin Workman Jan 03 '18 at 21:44

1 Answers1

0

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.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107