Slow Down Render

Hi all. Thanks for adding me. I’m building an LED project incorporating a Pixelblaze for the first time.

The sample effects run really fast. I want very slow, languid transitions. I saw another thread where the time() function was mentioned for use in slowing things down.

I am a C/C++ programmer, never used Java before. I’m looking at the sleep() and wait() functions, with a preference for sleep(). Are either of these appropriate to place in the beforeRender() function?

Thanks!

Hi @Jeffrey,
Welcome!

There’s no sleep() or wait() in the Pixelblaze language, to slow things down you’ll want to give a larger number to the time() functions. You can try typing in larger numbers, or if you want to change everything all at once, modify them to multiple their initial value by some variable which can be changed globally and in one place.

The time() function allows patterns to cycle through things over a period of time that is independent of how often the code is executed. This allows really smooth animations with a constant speed without tying them to the render frame rate. This also happens to mean that if you did cause a delay in rendering (like a busy loop counting to some high number), it wouldn’t slow the animations down, just reduce the frame rate. The argument given to time() tells it how long it wants between intervals, with about 65.5 seconds for a value of 1.

For example, here’s the starter pattern that makes a scrolling rainbow:

export function beforeRender(delta) {
  t1 = time(.1)
}

export function render(index) {
  h = t1 + index/pixelCount
  s = 1
  v = 1
  hsv(h, s, v)
}

Try changing the .1 value in the time(.1) call to something larger and it will slow down. An alternative method, imagine it was a more complicated pattern, is that you could control all of the speeds at the same time by using a multiplier variable like so:

var timeFactor = 10
export function beforeRender(delta) {
  t1 = time(.1 * timeFactor)
}

export function render(index) {
  h = t1 + index/pixelCount
  s = 1
  v = 1
  hsv(h, s, v)
}

With the new UI controls, you could also create a slider for it, something like this:

var timeFactor = 10
export function sliderSpeed(v) {
  timeFactor = 1 + v*10
}

export function beforeRender(delta) {
  t1 = time(.1 * timeFactor)
}

export function render(index) {
  h = t1 + index/pixelCount
  s = 1
  v = 1
  hsv(h, s, v)
}

You can upgrade just about every pattern by copying in those first 4 lines, then adding * timeFactor in the calls to time() to multiply the base speed the pattern already has.

Some patterns use the delta parameter in the beforeRender function, like KITT. Just like calls to time() this is another way of keeping track of time that isn’t tied to how often the code runs. You can modify these similarly and make the pattern think more or less time has passed by either modifying the delta parameter before the rest of the code uses it, or in the expression. Its an inverse relationship though, larger numbers mean more time has passed, so you’ll want to multiply by the reciprocal of timeFactor.

1 Like

Thanks for the quick reply! Glad I asked. I’ll try the sample code later today. A slider will be quite helpful.

1 Like