Hi @booli - I eventually just ended up setting all patterns the way I wanted them across my 6 PB by editing each pattern’s code on each of the 6 PB. I’m going to answer your question assuming you are just asking how I like to do my speed parameters on a single Pixelblaze. For this example, let’s assume the pattern relies on two timers. Imagine you found this in a pattern:
function beforeRender(delta) {
t1 = time(.1)
t2 = time(.03)
}
The first thing I like to do (just a personal preference) is to re-express these constants in terms of a period, in other words, a number I know is the number of seconds it will take to repeat. I usually round it off.
function beforeRender(delta) {
t1 = time(6.5 / 65.536) // t1 repeats every 6.5 seconds
t2 = time(2 / 65.536) // t2 repeats every 2 seconds
}
Then I like to make a global variable called speed
. To make the timers go faster when speed is increased, you need to take the period parameter in time and divide by speed
.
var speed = 1
function beforeRender(delta) {
// t1 repeats every 6.5 seconds, but if speed == 2, then 3.25 seconds.
t1 = time(6.5 / 65.536 / speed)
t2 = time(2 / 65.536 / speed)
}
This makes editing the speed of my patterns as easy as loading it and changing one number.
Sometimes I’ll define a UI slider that helps me play with different speeds. For example, if I wanted to let the slider go from quarter speed to 4X speed:
var speed = 1
export function sliderSpeed(_v) {
speed = .25 + 3.75 * _v)
// When slider is full left, _v == 0, speed is .25.
// When slider is full right, _v == 1, speed is 4.
}
function beforeRender(delta) {
// t1 repeats every 6.5 seconds, but if speed == 2, then 3.25 seconds.
t1 = time(6.5 / 65.536 / speed)
t2 = time(2 / 65.536 / speed)
}
If a pattern also uses delta
(the number of milliseconds elapsed since the last time beforeRender()
was called), you can scale that by speed as well. One way is to just overwrite the local variable delta inside beforeRender()
:
var speed = 1
function beforeRender(delta) {
// t1 repeats every 6.5 seconds, but if speed == 2, then 3.25 seconds.
t1 = time(6.5 / 65.536 / speed)
t2 = time(2 / 65.536 / speed)
delta = delta / speed
// <other stuff that uses delta here>
}
And to get really fancy, if you are up for the challenge of writing code outside Pixelblaze to send websockets messages to your PB programmatically, you can put an export
in front of var speed = 1
, and set your speed
variable from some other computer. This would be a path to simplify all patterns or sync speeds across multiple Pixelblazes.