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