Created
February 18, 2015 10:47
-
-
Save arnogues/2157a552cc8a5b520454 to your computer and use it in GitHub Desktop.
color converter
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
<h1>grayscale calculator</h1> | |
<input type="text" id="input" value="#DA0000" /> | |
<input type="text" id="output" /> | |
<script> | |
var inputField = document.getElementById('input'); | |
var outputField = document.getElementById('output'); | |
console.log(input); | |
inputField.onkeyup = function() { | |
inputvalue = input.value.replace(/#/,''); | |
val = inputvalue.match(/([\d\w]{2})/g); | |
console.log(val); | |
var gray = Math.ceil(0.299*parseInt(val[0],16) + 0.587*parseInt(val[1],16) + 0.114*parseInt(val[2],16)); | |
console.log(gray, gray.toString(16)); | |
output.value=new Array(4).join(gray.toString(16)); | |
console.log(output.value); | |
}; | |
input.onkeyup(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment