Hello,
I’m trying to run 2 or more patterns in one pattern on a 2D mapping.
Let’s say i have pattern1 running all the time, and when I click a toggle button, i want a second pattern to run on top. The best would be to give priority to the most “luminous” pixel of each pattern when displaying, but i can also live with layers (if a pixel is ON in layer 1 for example, it is displayed regardless of the pixel status in layer 2).
The idea is to basically be able to take a manual input to activate/deactivate some effects without changing the pattern, for example to select appropriate animations manually depending of the music (if we’re in buildup, break, full on…) on a festival stage.
I created the code below (DO NOT RUN IT !), and put each pattern calculation (based on x/y since i have a 2D mapping) in sub functions:
//Program to test the ability of having 2 or more separate animations in 1 pattern
//Define working variables specific to the 2D mapping
pixelColumns = 9
pixelHeight = pixelCount / pixelColumns
//Define arrays to render separately the patterns
var hsvPattern1 = [1, 1, 1]
var hsvPattern2 = [1, 1, 1]
//Button to activate second pattern or not
var tooglePattern2 =0
// Toggle to activate or not a sub pattern
export function togglePattern2(c) {
tooglePattern2 = c
}
//----------------------------------------------------------
export function beforeRender(delta) {
t1 = time(.1)
}
//----------------------------------------------------------
export function render2D(index,x,y) {
pattern1(index,x,y)
//Apply pattern 1 to hsv
h = hsvPattern1[0]
s = hsvPattern1[1]
v = hsvPattern1[2]
pattern2(index,x,y)
// Apply pattern 2 to hsv only if luminosity of pattern 2 is higher AND if we have activated it
if (hsvPattern2[2] > v && tooglePattern2 == 1){
h = hsvPattern2[0]
s = hsvPattern2[1]
v = hsvPattern2[2]
}
hsv(h, s, v)
}
//----------------------------------------------------------
// Calculation of a frame of pattern 1
export function pattern1(index,x,y) {
hsvPattern1 = [y+t1, 1, 1]
}
// Calculation of a frame of pattern 2
export function pattern2(index,x,y) {
hsvPattern2 = [1, 1, y]
}
I obviously did a mistake because it sends my FPS to 0.01 and almost froze my Pixelblaze (couldn’t change to another pattern). Didn’t expect it…
I’m kinda struggling with this. Can someone help me understand WHY this code kills the CPU ? I feel i don’t get the logic behind render2D…
Thank you !