Two patterns seem to reference the same underlying code

Pattern CS No22 is an excellent smo-mo pattern that works well with my display. The problem is that it can’t be duplicated. If I change the colors around and want to save the new setup, even after I completely rename said sketch, CS No22 and the new one Beautiful Slo-Mo (same sketch, different colors and patterns) will both be the same!

That’s really odd. Can you export the .epe and post it here so I can see if I can replicate the problem?

Better yet, you can just download it from the patterns list. It’s where I got it.

t/*
  To get started, pick some colors, like Color 1 through Color 4. 
  
  Sequences is a pattern optimized for lights on spaced strands
  (not strips) installed in long lines such as on houses. You 
  choose the colors that will be used in a repeating seqence.
  
  This pattern was designed for https://mypixellights.com/
  
  On long installs with many pixels, enabling many of the 
  effects may slow down the framerate enough to be choppy.
  
  Jeff Vyduna, 2021, MIT License
*/

// You only need this on PB v2! Remove it on a Pixelblaze v3 for faster, smoother animations
function mod(dividend, divisor) {
  var res = dividend % divisor
  if ((res != 0) && (res > 0) != (divisor > 0)) { //this compares the sign of both
    res += divisor
  }
  return res
}

var MAX_COLOR_COUNT = 12 // If you raise this, you'll need to add more RGBPickers below.
var R = array(MAX_COLOR_COUNT)
var G = array(MAX_COLOR_COUNT)
var B = array(MAX_COLOR_COUNT)
R[0] = 1; B[1] = 1 // Default colors for first load

var segLength = 1, fadeLen = segLength - 1
var MAX_SEGMENT_LENGTH = pixelCount * 3
export function sliderColorLength (_v) {
  segLength = ceil(_v * _v * _v * (MAX_SEGMENT_LENGTH - 1) + .001)
  fadeLen = segLength - 1
}

var chaseSpeed = .05, chaseSpeedSlider = .5
export function sliderChaseSpeed (_v) {
  chaseSpeedSlider = _v
  chaseSpeed = _v - .5
  if (abs(chaseSpeed) < .1) { // Wide null zone in the middle
    chaseSpeed = 0
  } else { 
    chaseSpeed += (chaseSpeed > 0 ? -1 : 1) * .1
    chaseSpeed *= 2.5
  }
  chaseSpeed = 4 * pow(chaseSpeed, 5) // Very nonlinear response to allow very slow speeds
}

var fadeOut = 0, fadeRun
export function sliderFadeOut(_v) { 
  fadeOut = _v * _v
}

var smoothing = 1, easeInOutExp
export function sliderColorSmoothing(_v) { 
  smoothing = _v 
  var s0 = 1 - smoothing
  easeInOutExp = 1 / (1 + 40 * s0 * s0 * s0) // the exponential power
}

var twinkleWhite = 0, twinkleWhitePeriod
export function sliderTwinkleWhite(_v) { 
  twinkleWhite = _v
  twinkleWhitePeriod = pixelCount * (1 - .9 * twinkleWhite)
}

var twinkleOff = 0, twinkleOffPeriod
export function sliderTwinkleOff(_v) { 
  twinkleOff = _v 
  twinkleOffPeriod = pixelCount * (1 - .99 * sqrt(sqrt(twinkleOff)))
}

var blinkSlider = 0, blinkPeriod
export function sliderBlink(_v) { 
  blinkSlider = _v
  blinkPeriod = 2 + 58 * (1-_v) * (1-_v) // A short blink once every 2 to 60 seconds
}

var colorCount = 4
export function sliderNumberOfColorsUsed(_v) {
  colorCount = ceil(_v * (MAX_COLOR_COUNT - 1) + .001)
}

export function rgbPickerColor_1(_r, _g, _b)  { R[0]  = _r; G[0]  = _g; B[0]  = _b }
export function rgbPickerColor_2(_r, _g, _b)  { R[1]  = _r; G[1]  = _g; B[1]  = _b }
export function rgbPickerColor_3(_r, _g, _b)  { R[2]  = _r; G[2]  = _g; B[2]  = _b }
export function rgbPickerColor_4(_r, _g, _b)  { R[3]  = _r; G[3]  = _g; B[3]  = _b }
export function rgbPickerColor_5(_r, _g, _b)  { R[4]  = _r; G[4]  = _g; B[4]  = _b }
export function rgbPickerColor_6(_r, _g, _b)  { R[5]  = _r; G[5]  = _g; B[5]  = _b }
export function rgbPickerColor_7(_r, _g, _b)  { R[6]  = _r; G[6]  = _g; B[6]  = _b }
export function rgbPickerColor_8(_r, _g, _b)  { R[7]  = _r; G[7]  = _g; B[7]  = _b }
export function rgbPickerColor_9(_r, _g, _b)  { R[8]  = _r; G[8]  = _g; B[8]  = _b }
export function rgbPickerColor_10(_r, _g, _b) { R[9]  = _r; G[9]  = _g; B[9]  = _b }
export function rgbPickerColor_11(_r, _g, _b) { R[10] = _r; G[10] = _g; B[10] = _b }
export function rgbPickerColor_12(_r, _g, _b) { R[11] = _r; G[11] = _g; B[11] = _b }

var randoms = array(pixelCount + 1)
for (i = 0; i <= pixelCount; i++) randoms[i] = random(1)



var animTimer, animOffset, blink
export function beforeRender(delta) {
  animTimer = mod(animTimer + delta * chaseSpeed / 512, 1) // bidirecional - chaseSpeed is -n..n
  animOffset = -animTimer * segLength * colorCount
  blink = blinkSlider ? blinkFn() : 1
}

export function render(index) {
  var colorIdx = mod(floor((index + animOffset) / segLength), colorCount)
  var nextColorIdx = (colorIdx + 1) % colorCount
  
  var skipSmoothingBlack = fadeOut != 0
  if (smoothing > 0 && fadeOut > 0) {
    skipSmoothingBlack = (
         R[nextColorIdx] < .01  && G[nextColorIdx] < .01 && B[nextColorIdx] < .01 
      || R[colorIdx] < .01      && G[colorIdx] < .01     && B[colorIdx] < .01
    )
  }
  
  if (skipSmoothingBlack || smoothing == 0) {
    blendedR = R[colorIdx]; blendedG = G[colorIdx]; blendedB = B[colorIdx]
  } else { // Color smoothing (blending)
    var blendPct = mod((index + animOffset), segLength) / segLength
    
    var easeFn = (fadeOut == 0) ? easeInOut : easeIn
    blendPct = easeFn(blendPct, smoothing)

    blendRGB(R[colorIdx], G[colorIdx], B[colorIdx], 
             R[nextColorIdx], G[nextColorIdx], B[nextColorIdx],
             blendPct)
  }
  
  var fade = fadeFn(mod(index + floor(animOffset), segLength))
  
  var twinkleOV = 1
  var twinkleWV = twinkleWhite == 0 || .25
  var tBoostWhite = 0
  
  // Twinkle only pixels that are bright enough
  if ((blendedR + blendedG + blendedB) * fade > .4) {
    if (twinkleWhite) {
      var twinkleTimer = randoms[(pixelCount + index + animOffset) % pixelCount]
      //             duration, total cycle length, phase offset, max peak
      twinkleWV = twinkleFn(1, twinkleWhitePeriod, twinkleTimer, 5)
      if (twinkleWV > 1) tBoostWhite = (twinkleWV - 1) / 4
      twinkleWV %= 1 // Flash the white peak
    }
  
    if (twinkleOff) {
      var twinkleOffTimer = randoms[(pixelCount*3/2 + index + animOffset) % pixelCount]
      var twinkleOV = 1.25 - twinkleFn(6, twinkleOffPeriod, twinkleOffTimer, 1.25)
    }
  }
  
  fade *= fade * fade * twinkleWV * twinkleOV * blink

  rgb(blendedR * fade + tBoostWhite, 
      blendedG * fade + tBoostWhite,
      blendedB * fade + tBoostWhite)
}

// https://www.desmos.com/calculator/kfoqvjjw32
// Given x from 0..1, return in-out easing from 0..1, given parameter s: "smoothness" where 0 = linear and 1 = instantaneous
function easeInOut(x, s) {
  if (smoothing == 0) return x >= .5
  if (smoothing == 1) return x

  if (x < .5) { // Had to do it two sided, as pow(-27, 1/3) doesn't return -3
    x = 1 - x
    return 1 - (pow((2 * x - 1), easeInOutExp) + 1) / 2
  } else {
    return (pow((2 * x - 1), easeInOutExp) + 1) / 2
  }
}

// Given x from 0..1, return easing - in from 0..1, given parameter s: "smoothness" where 0 = linear and 1 = instantaneous
function easeIn(x, s) {
  if (s == 0) return 0
  if (s == 1) return x
  s = (s + 1) / 2
  s = 1 - s
  s = s * s * s * s
  return pow(x, 1 + 100 * s)
}

// Gixen x in 0..segLength, retun a variable fadeout sawtooth
// Shoutout - thanks for the help, ZRanger1
function fadeFn(x) {
  if (fadeOut == 0) return 1
 
  var v = 1 - (fadeOut * 4 * ((chaseSpeedSlider < .5) ? x : fadeLen - x) / fadeLen)
  return v * v * v
}

// Blend two colors via additive weighted average
var blendedR, blendedG, blendedB
function blendRGB(r1, g1, b1, r2, g2, b2, pct2) {
  pct1 = 1 - pct2
  blendedR = pct1 * r1 + pct2 * r2
  blendedG = pct1 * g1 + pct2 * g2
  blendedB = pct1 * b1 + pct2 * b2
}

/*
  Twinkle from .25 to 1 (or higher)
    tD - twinkle duration, in seconds
    period - total cycle length in seconds
    offset - phase offset as a percent of `period`. Pass negative 
        offsets to repeat twinkle for that percent of `period`
    peak - when 0, max return value is 1. When higher, peak is higher, 
      and if limited to 1 (by clamp() or hsv()), you get longer peak duration 
    
    See https://www.desmos.com/calculator/gedneqiqih
*/
function twinkleFn(tD, period, offset, peak) {
  var t = period * ((time(period / 65.536) + offset) % 1)
  tD = min(tD, period)
  if (t < tD) {
    var v = abs(sin((t / tD + .5) * PI)) + 1
    return (peak + 1.5) * (1 / v - .5) + .25
  } else {
    return .25
  }
}

function blinkFn() {
  var blinkNow = time(blinkPeriod / 65.536) < .3 / blinkPeriod
  return 1 - blinkNow * square(time(.001525), .5)
}


ype or paste code here

Ahhh - I actually named this Custom Sequences when I uploaded it to the pattern library. That’s why I didn’t recognize “CS No22”. It’s quite different from (and not related to) the Music Sequencer.

I tried it on my own Pixelblaze and I’m not seeing the same problem with two instances actually referencing the same underlying code edits. It must be something specific (or corrupted) on your Pixelblaze. Do you have a lot of patterns on this particular controller? I haven’t seen something like this but if you power-cycle the controller and take a screencast, (upload to a YouTube unlisted link), I’m interested to see and confirm the behavior.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.