White Balance/Color Temp

For @wicked1 and anybody else who needs to adjust white levels, Here’s a short example that shows white balancing in hsv-based patterns: (I have some highly blue tinted LEDs myself this year!)

// Quick and dirty white balancing for hsv patterns
//
// 11/29/2021  ZRanger1

// call this function at pattern initialization with the RGB values
// that produce the best white on your display.
// Input values should be in the range 0.0 to 1.0 or very
// strange things will happen.
var rBal = 1; gBal = 1; bBal = 1;
function setWhite(r,g,b) {
  rBal = r;
  gBal = g;
  bBal = b;
}

// call this in your pattern instead of the default hsv()
// simple, quick HSV to RGB algorithm adapted from random GLSL
function hsv_balanced(h,s,v) {
  var r,g,b;

  h = h * 6;
  
  r = (h+5) % 6;
  r = v - v * s * max(min(min(r,4-r),1),0);
  
  g = (h+3) % 6;
  g = v - v * s * max(min(min(g,4-g),1),0);
  
  b = (h+1) % 6;
  b = v - v * s * max(min(min(b,4-b),1),0);
  
  rgb(r*rBal,g*gBal,b*bBal);
}

// change the values in the call to setWhite to
// what looks best on your system.
setWhite(1,1,1)

export function beforeRender() {
  ;
}

// shows full LED white on first half of display,
// "balanced" white on second half.
export function render(index) {
  p = index/pixelCount;
  h = 0
  s = 0
  v = 1
  if (p < 0.5) {
    hsv(h, s, v)
  }
  else {
    hsv_balanced(h,s,v);
  }
}
4 Likes