Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Last active September 8, 2016 08:49
Show Gist options
  • Save mohayonao/942b2f67993328cf82229f85b64e0513 to your computer and use it in GitHub Desktop.
Save mohayonao/942b2f67993328cf82229f85b64e0513 to your computer and use it in GitHub Desktop.
// velocity-for-color
// https://github.com/brunchboy/afterglow/blob/master/src/afterglow/controllers/ableton_push.clj#L24
module.exports = (h, s, v) => {
if (v < 3) {
return 0;
}
const brightnessShift = (60 < v) ? 0 : (37 < v) ? 1 : (15 < v) ? 2 : 3;
if (s < 20) {
return Math.min(4 - brightnessShift, 3);
}
const baseHue = h;
const adjustedHue = baseHue > 230 ? Math.min(baseHue * 1.2, 360) : baseHue;
const hueSection = 4 + 4 * Math.floor(13 * adjustedHue / 360);
return hueSection + brightnessShift;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment