feat: multibit support for rgb lights
This commit is contained in:
parent
1515c1b991
commit
3c59690f30
|
@ -24,6 +24,8 @@ const lightTemplate: PartialTemplate = {
|
||||||
activation: `
|
activation: `
|
||||||
const { main, active } = context.colors
|
const { main, active } = context.colors
|
||||||
|
|
||||||
|
const bits = context.get(0)
|
||||||
|
|
||||||
context.color(parseInt(context.get(0),2) ? active : main)
|
context.color(parseInt(context.get(0),2) ? active : main)
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,15 +22,20 @@ const rgbLightTemplate: PartialTemplate = {
|
||||||
},
|
},
|
||||||
code: {
|
code: {
|
||||||
activation: `
|
activation: `
|
||||||
const get = (index) => context.getBinary(index) & 1
|
const get = (index) => context.get(index)
|
||||||
const color = (get(0) << 2) + (get(1) << 1) + get(2)
|
|
||||||
|
|
||||||
if (color === 0){
|
const colors = Array.from({ length: 3 }, (_, index) => {
|
||||||
|
const bits = get(index)
|
||||||
|
const max = 2 ** bits.length - 1
|
||||||
|
return 256 * parseInt(bits, 2) / max
|
||||||
|
})
|
||||||
|
|
||||||
|
if (colors.reduce((curr, acc) => acc + curr, 0) === 0){
|
||||||
context.color(context.colors.main)
|
context.color(context.colors.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
context.color(context.colors[color])
|
context.color(\`rgb(\${colors.join(",")})\`)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue