Multiple Color Pickers and Arrays?

[Edit: Sorry, somewhat duplicative of @Nick_W’s excellent help, we must’ve been replying at the same time]

See this thread for the best alternative, but I’ve basically given up on it and prefer to have spare Pixelblazes and code directly on them, even with no LEDs attached (just using the preview bar on the web page).

Yes, but I’ve heard it called “operator precedence” in software engineering. Here’s a good guide for JavaScript which should work for Pixelblaze.

Nope! Shouldn’t be.

No! Looks pretty straightforward to me – great job! Since making that original “Christmas string lights” pattern a while ago, I’ve gotten much fancier with my twinklers. When you want to have a look at that, check out “Twinkling Classic Xmas Strands” on the pattern library (currently on page 2), as well as the following code that emulates candle twinkling.

candles

Candles / Flickerers

// Flickering candle idea from 
// https://cpldcpu.wordpress.com/2013/12/08/hacking-a-candleflicker-led/

var flickerMode = 1
export function sliderFlickerMode(_v) { flickerMode = _v > .5 }


var tBcount = 32
var tBs = array(tBcount) // List of Target Brightness values
for (i = 0; i < tBcount; i++ ) tBs[i] = 1
var tBVals // Count of actual target brightnesses added
add = (b) => { tBs[tBVals] = b; tBVals++ } // Convenience, creating a frequency distribution
add(.9); add(.9); add(.9); add(.9); 
add(.9); add(.9); add(.9); add(.8); 
add(.7); add(.6); add(.5); add(.4); 
add(.3); add(.2); add(.1); add(.9);


candles = 8
candleLen = ceil(pixelCount / candles) // in pixels

var nextTransitionAts = array(candles)
var transitionTimes = array(candles)
var targetVs = array(candles)
var currentVs = array(candles)

var accumDeltas = 0

// Set new target brightness and transition time for a given candle
function setTargets(c) {
  transitionTimes[c] = 1000 * (.2 + random(.1)) // Candles recover from disturbances at 5Hz
  nextTransitionAts[c] = accumDeltas + transitionTimes[c] // We all happily overflow together
  targetVs[c] = tBs[random(tBcount)]
}
for (c = 0; c < candles; c++) { currentVs[c] = 1; setTargets(c) }

var tf, t1
export function beforeRender(delta) {
  accumDeltas += delta

  for (c = 0; c < candles; c++) {
    nextTransitionAts[c] < accumDeltas ? setTargets(c) : 0
    currentVs[c] += (targetVs[c] - currentVs[c]) * delta / transitionTimes[c]
  }
  
  t1 = triangle(time(.1))
  tf = time(.006)
}

var h, s, v
export function render(index) {
  candle = floor(index / candleLen)
  if (candle % 2 == 0) { hsv(0, 0, 0); return } // Candle every three
  
  h = .06; s = .95; v = currentVs[candle]
  
  if (flickerMode == 1) fMode1(index)
  
  candleShape = wave(candles * index / pixelCount-.25)
  hsv(h, sqrt(s), v * v * candleShape * candleShape)
}

// Experimental personal preferences for colors and frequency
function fMode1(index) {
  if (v < .9) { // Flickering
    inv = 1 - v
    v *= v + inv * wave(10 * v * index / pixelCount + tf)
    s = .95 + .12 * inv
    h = .03 - .02 * inv
  } else { // Not flickering
    h = .05 + .02 * t1
    s = .9
  }
}

1 Like