```
/*
Multiple SubMaps with multiple patterns v1.0 - by ScruffyNerf
inspired by various code bits by zranger, Jeff Vyduna and Ben Hencke
Very Simple demo version, a truly minimal example (2 ranges, 2 patterns)
There are lot of ways to do what this pattern does without using multiple maps, it's for building on.
Requirements: Matrix with a 2D map
*/
// these functions can take index,x,y and modify a set of globals to use instead
// isInMap is set to true, if the pixel is in this submap
// NewIndex is the "new" index value, if any [NOT USED IN EXAMPLE]
// NewPixelCount is the pixelcount of the new map, if any [NOT USED IN EXAMPLE]
// NewX is the new value of x for that pixel, might be renormalized, might not, still in range of 0..1
// NewY is the new value of y for that pixel, might be renormalized, might not, still in range of 0..1
var isInMap
var NewIndex = 0;
var NewPixelCount = 0;
var NewX,NewY
var t1
// These are the map functions it will consider.
// Order matters, it will consider only the FIRST return of true
// This allows overlapping maps, with the first (0) being "on top",
// and potentially this also allows a background/default map (matching none of the submaps listed)
var mapCount = 5 // number of maps+patterns
var maps = array(mapCount)
maps[0] = inmap0
maps[1] = inmap1
maps[2] = inmap2
maps[3] = inmap3
maps[4] = inmap4
export function beforeRender(delta) {
t1 = time((.5) / 65.536) // From 0…1 every 4 seconds
}
// maps[2] = your map functions go here
function inmap0(index, x, y) {
if (x < 1 && y > .99) {
isInMap = true;
}
}
function inmap1(index, x, y) {
if (x < 1 && y > .88 ) {
isInMap = true;
}
}
function inmap2(index, x, y) {
if (x < 1 && y > .8) {
isInMap = true;
}
}
function inmap3(index, x, y) {
if (x < 1 && y > .12) {
isInMap = true;
}
}
function inmap4(index, x, y) {
if (x < 1 && y > .00) {
isInMap = true;
}
}
// if you are learning how this works, I recommend adding a new map first, and experimenting...
// then add a new pattern (You'll want to just copy a pattern for the new map. Map # matches Pattern # for simplicity )
var patterns = array(mapCount)
patterns[0] = pulseBlue
patterns[1] = pulseGreen
patterns[2] = pulseRed
patterns[3] = pulseviolet
patterns[4] = pulsecf
// patterns[2] = your pattern function(s) goes here
function pulseBlue(index,x,y){
hsv(.6, 1, wave(time(.02)))
}
function pulseGreen(index,x,y) {
hsv(.3, 1, triangle(time(.04)))
}
function pulseRed(index,x,y) {
hsv(.01, 1, wave(time(.008)))
}
function pulseviolet(index,x,y) {
hsv(.8, 1, wave(time(.0008)))
}
function pulsecf(index,x,y) {
hsv(.2, 1, wave(time(.001)))
}
export function render2D(index, x, y) {
matched = false;
NewPixelCount = pixelCount;
NewIndex = index;
NewX = x;
NewY = y;
for (var p = 0; p < mapCount; p++) {
isInMap = false;
maps[p](index, x, y);
if (isInMap) {
patterns[p](NewIndex,NewX,NewY);
matched = true; // to avoid turning light off
p = mapCount; // stop the for loop
}
}
if (matched == false) {
// no match, no light
v = clamp((triangle((y/0.5) - t1 + 0.5) -.5) * .5, 0, 1)
hsv((t1 / 0.3)* 0.2, 1, v * v)
}
}
// just so it'll render in 1D
export function render(index) {
render2D(index, index / pixelCount, 0)
}
```