处理中基于时间的事件 [英] Timing based events in Processing

查看:30
本文介绍了处理中基于时间的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个音乐可视化器,并为此创建一个数组,该数组可以按音乐中出现的顺序保护指令.然后,我想构建一个函数,以设定的速度解析数组并执行指令.

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.

因此,例如,我有一个包含{a,b,a,b,a}的数组,并且对于每一个a,屏幕都会变成红色,而对于每b,屏幕都会变成黑色.

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.

我尝试使用Threads和sleep()函数,但不会再次唤醒.坦白地说,我对下一步的工作一无所知.

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.

推荐答案

您可以使用 modulo 运算符以及 frameCount 变量每隔 X 帧做某事.

You could use the modulo operator along with the frameCount variable to do something every X frames.

下面是一个小示例,它每 60 帧或每秒一次更改背景:

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));
  }
}

这使用硬编码的 60 每秒更改一次背景,但是您可以从数组中获取该数字.

This uses hard-coded 60 to change the background once per second, but you could get that number from an array instead.

这篇关于处理中基于时间的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆