Hi all,
I’ve been coming here for a few months now, always asking questions, so I thought it was time to give something back to the community. A small disclaimer, I’m really bad at coding -actually I had 0 experience before getting a PB- so the patterns below are the result of a lot of trial and error, copy/paste from other patterns and plenty of questions in the forum. I’m not sure they are 100% correct from a coding perspective and I wouldn’t dare uploading them to the library so feel free to suggest corrections!
First one is a simple static color pattern that divides your strip in 3 segments and lets you choose color and length of each segment. I know that PB is capable of all sorts of 3D mapped extravaganza, but sometimes(including the project I made this for) all you need is static in glorious 1D:)
3 Segment Static
//Colour Picker 1
export function hsvPickerColour1(h, s, v) {
hue1 = h
saturation1 = s
value1 = v
}
//Colour Picker 2
export function hsvPickerColour2(h, s, v) {
hue2 = h
saturation2 = s
value2 = v
}
//Colour Picker 3
export function hsvPickerColour3(h, s, v) {
hue3 = h
saturation3 = s
value3 = v
}
export var depth1
export function sliderDepth1(v) {
depth1 = floor(v * pixelCount );
}
export var depth2
export function sliderDepth2(v) {
depth2 = floor(v * (pixelCount - depth1) );
}
export function render(index) {
if (index >= depth1 + depth2) { // everything after depth2
hue = hue3
saturation = saturation3
value = value3
}
else if (index >= depth1) { // after depth1
hue = hue2
saturation = saturation2
value = value2
}
else { // from 0 to end of depth1
hue = hue1
saturation = saturation1
value = value1
}
hsv(hue, saturation, value)
}
Here’s another version of the above, but with a potentiometer added in the code to control overall brightness connected to pin 4 of the expansion board.
3 Segment Static with Pot
export var analogInputs
export var potAverage
//Colour Picker 1
export function hsvPickerColour1(h, s, v) {
hue1 = h
saturation1 = s
value1 = v
}
//Colour Picker 2
export function hsvPickerColour2(h, s, v) {
hue2 = h
saturation2 = s
value2 = v
}
//Colour Picker 3
export function hsvPickerColour3(h, s, v) {
hue3 = h
saturation3 = s
value3 = v
}
export var depth1
export function sliderDepth1(v) {
depth1 = floor(v * pixelCount );
}
export var depth2
export function sliderDepth2(v) {
depth2 = floor(v * (pixelCount - depth1) );
}
function updateAverageForPot() {
var weight = 0.03
potAverage = (potAverage*(1-weight)) + analogInputs[4] * weight
}
export function beforeRender(delta) {
updateAverageForPot()
}
export function render(index) {
if (index >= depth1 + depth2) { // everything after depth2
hue = hue3
saturation = saturation3
value = value3 * potAverage
}
else if (index >= depth1) { // after depth1
hue = hue2
saturation = saturation2
value = value2 * potAverage;
}
else { // from 0 to end of depth1
hue = hue1
saturation = saturation1
value = value1 * potAverage
}
hsv(hue, saturation, value)
}
Here’s a 5 Segment version of the above:
5 Segment Static
//Colour Picker 1
export function hsvPickerColour1(h, s, v) {
hue1 = h
saturation1 = s
value1 = v
}
//Colour Picker 2
export function hsvPickerColour2(h, s, v) {
hue2 = h
saturation2 = s
value2 = v
}
//Colour Picker 3
export function hsvPickerColour3(h, s, v) {
hue3 = h
saturation3 = s
value3 = v
}
//Colour Picker 4
export function hsvPickerColour4(h, s, v) {
hue4 = h
saturation4 = s
value4 = v
}
//Colour Picker 5
export function hsvPickerColour5(h, s, v) {
hue5 = h
saturation5 = s
value5 = v
}
export var depth1
export function sliderDepth1(v) {
depth1 = floor(v * pixelCount );
}
export var depth2
export function sliderDepth2(v) {
depth2 = floor(v * (pixelCount - depth1) );
}
export var depth3
export function sliderDepth3(v) {
depth3 = floor(v * (pixelCount - depth2) );
}
export var depth4
export function sliderDepth4(v) {
depth4 = floor(v * (pixelCount - depth3) );
}
export function render(index) {
if (index >= depth1 + depth2 + depth3 + depth4) { // everything after depth4
hue = hue5
saturation = saturation5
value = value5
}
else if (index >= depth1 + depth2 + depth3) { // everything after depth3
hue = hue4
saturation = saturation4
value = value4
}
else if (index >= depth1 + depth2) { // everything after depth2
hue = hue3
saturation = saturation3
value = value3
}
else if (index >= depth1) { // after depth1
hue = hue2
saturation = saturation2
value = value2
}
else { // from 0 to end of depth1
hue = hue1
saturation = saturation1
value = value1
}
hsv(hue, saturation, value)
}
Last one is a simple chaser, based on the KITT pattern. You can control color, speed, background brightness, tail length and interval via sliders.
Chaser
leader = 0
pixels = array(pixelCount)
export function sliderHue(v) {
Hue = (v);
}
export var speed
export function sliderSpeed(v) {
speed = (v / 12 +.01);
v= v* v * v
}
export function sliderBackground(v) {
spread = (v);
}
export function sliderInterval(v) {
int = (v / 10);
}
export function sliderTail(v) {
fade = ((1-v) /300 +0.00016 );
}
export function beforeRender(delta) {
lastLeader = floor(leader)
leader += delta * speed
if (leader >= (pixelCount + 1 )) {
t1=time(int)
if (t1>=0.9) leader = 0
} else {
for (i = lastLeader; i != floor(leader); i++) pixels[i] = 1
}
for (i = 0; i < pixelCount; i++) {
pixels[i] -= delta * fade
pixels[i] = max(clamp(spread, 0.13, 0.9), pixels[i])
}
}
export function render(index) {
v = pixels[index]
v = v * v * v
h = (v > 0.002) ? 0 : 1
hsv(Hue, 1, ((h == 0) ? v : 0.5) )
}
That’s it, many thanks to @wizard , @Scruffynerf , @zranger1 and @Jeff for the help:)