# White Balance/Color Temp

**URL:** <https://forum.electromage.com/t/white-balance-color-temp/1774>\
**Category:** Uncategorized\
**Created:** [November 29, 2021, 2:07am UTC](https://forum.electromage.com/t/white-balance-color-temp/1774 "2021-11-29T02:07:53Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [November 29, 2021, 6:04pm UTC](https://forum.electromage.com/t/white-balance-color-temp/1774/7 "2021-11-29T18:04:12Z")

</div>

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!)

```auto
// 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);
  }
}

```

---

_[View the full topic](https://forum.electromage.com/t/white-balance-color-temp/1774)._
