Created
August 26, 2016 13:34
-
-
Save Munter/698a5bd99a9c444862b200b368bb4f6a to your computer and use it in GitHub Desktop.
Lighting control program for JSConf Iceland northern lights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { totalCols } = config | |
function crazyCaterpillar(time) { | |
const newLights = new Lights() | |
let dead = []; | |
for (let i = 0; i < 3; i++) { | |
dead.push(Math.round(Math.random() * totalCols)); | |
} | |
for (let i = 0; i < totalCols; i++) { | |
if (dead.indexOf(i) === -1) { | |
const hue1 = (Math.round(360 / (totalCols / 2) * i) + (time * 300)) % 360; | |
const hue2 = (Math.round(360 / (totalCols / 2) * (totalCols - i)) + (time * 400)) % 360; | |
let saturation1 = 100; | |
let saturation2 = 80; | |
let lightness1 = (Math.sin(time * 10) + 1.0) * 20 + 30; | |
let lightness2 = (Math.sin(time * 10) + 1.0) * 20 + 30; | |
if (time % 1 < 0.02) { | |
lightness1 = 10; | |
} | |
if (time % 1 > 0.04 && time % 1 < 0.08) { | |
lightness2 = 90; | |
} | |
const color1 = Color().hsl(hue1, saturation1, lightness1); | |
const color2 = Color().hsl(hue2, saturation2, lightness2); | |
newLights.set(i, color1, color2); | |
} | |
} | |
return newLights | |
} | |
function pride(time) { | |
const newLights = new Lights() | |
let dead = []; | |
time = Math.sin(time) + 1; | |
for (let i = 0; i < 0; i++) { | |
dead.push(Math.round(Math.random() * totalCols)); | |
} | |
for (let i = 0; i < totalCols; i++) { | |
if (dead.indexOf(i) === -1) { | |
const hue1 = (Math.round(360 / (totalCols / 2) * i) + (time * 400)) % 360; | |
const hue2 = (Math.round(360 / (totalCols / 2) * (totalCols - i)) + (time * 400)) % 360; | |
let saturation1 = 100; | |
let saturation2 = 80; | |
let lightness1 = (Math.sin(time * 10) + 1.0) * 20 + 30; | |
let lightness2 = (Math.sin(time * 10) + 1.0) * 20 + 30; | |
const color1 = Color().hsl(hue1, saturation1, lightness1); | |
const color2 = Color().hsl(hue2, saturation2, lightness2); | |
newLights.set(i, color1, color2); | |
} | |
} | |
return newLights | |
} | |
function rolling(time) { | |
const newLights = new Lights() | |
newLights.set(Math.floor(time * 60 % totalCols), Color().hsl(0, 100, 50)); | |
newLights.set(Math.floor(totalCols - (time * 60 % totalCols)), Color().hsl(260, 100, 50)); | |
newLights.set(Math.floor(time * 90 % totalCols), Color().hsl(100, 100, 50)); | |
newLights.set(Math.floor(totalCols - (time * 90 % totalCols)), Color().hsl(150, 100, 50)); | |
newLights.set(Math.floor(time * 50 % totalCols), Color().hsl(60, 100, 50)); | |
newLights.set(Math.floor(totalCols - (time * 50 % totalCols)), Color().hsl(120, 100, 50)); | |
newLights.set(Math.floor(time * 30 % totalCols), Color().hsl(180, 100, 50)); | |
newLights.set(Math.floor(totalCols - (time * 20 % totalCols)), Color().hsl(240, 100, 50)); | |
return newLights | |
} | |
function update(currentLights, time) { | |
//return rolling(time) | |
if (time % 15 < 5) { | |
return rolling(time) | |
} else if (time % 15 < 10) { | |
return pride(time); | |
} else { | |
return crazyCaterpillar(time); | |
} | |
} | |
// Registers a visualization. | |
register(update) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment