Last active
April 1, 2017 19:41
-
-
Save mjswensen/42caa39bf8d21fb7082519ea6476ba8b to your computer and use it in GitHub Desktop.
Quick node script for calculating an even distribution between two given colors.
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
#!/usr/bin/env node | |
const dark = process.argv[2]; | |
const light = process.argv[3]; | |
const count = parseInt(process.argv[4], 10) + 1; | |
const matcher = /#?([\w]{2})([\w]{2})([\w]{2})/; | |
const darkParsed = matcher.exec(dark); | |
const darkR = parseInt(darkParsed[1], 16); | |
const darkG = parseInt(darkParsed[2], 16); | |
const darkB = parseInt(darkParsed[3], 16); | |
const lightParsed = matcher.exec(light); | |
const lightR = parseInt(lightParsed[1], 16); | |
const lightG = parseInt(lightParsed[2], 16); | |
const lightB = parseInt(lightParsed[3], 16); | |
const rInterval = (lightR - darkR) / count; | |
const gInterval = (lightG - darkG) / count; | |
const bInterval = (lightB - darkB) / count; | |
console.log(`(${dark})`); | |
for (let i = 1; i < count; i++) { | |
console.log(`#${Math.round(darkR + rInterval * i).toString(16).toUpperCase()}${Math.round(darkG + gInterval * i).toString(16).toUpperCase()}${Math.round(darkB + bInterval * i).toString(16).toUpperCase()}`); | |
} | |
console.log((`(${light})`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment