PrateekSaxena Posted December 30, 2006 Share Posted December 30, 2006 Hello,I am trying to make a color picker in JavaScript. This is how the photoshop and the MSPaint color picker looks- PhotoShop 7MS Paint Ok, now what I am wondering is that how it should look? We all know that a color is made up of RGB values. Each of them can have differnet valus from 0 to 255, making it a total 64770 colors. So how do I allow the user to choose the color? How do I show him/her all the colors that aree available in a limited space of say about 250px by 250px :ph34r: . Also could you please tell me how I can convert HEX number into INT and INT numbers into HEX.Thank you very much in advance! Link to comment Share on other sites More sharing options...
Webworldx Posted December 31, 2006 Share Posted December 31, 2006 Hiya Prateek, i'm a huge fan of this one: http://www.ficml.org/jemimap/style/color/wheel.html, so any basing on that with a more advanced selection feature would be a gem =)When you say hex into int, do you mean hex into rgb or something else? Link to comment Share on other sites More sharing options...
jesh Posted January 2, 2007 Share Posted January 2, 2007 Here's a hexadecimal to decimal convertor that I put together and use for a number of projects: function toDec(hex){ if(!hex.match(/^[0-9a-f]+$/i)) { return NaN; } hex = hex.toLowerCase(); var chars = "0123456789abcdef"; var length = hex.length; var currentDigit = 0, power = 0, sum = 0; for(var i = (length - 1); i >= 0; i--) { currentDigit = chars.indexOf(hex.charAt(i)); sum += currentDigit * Math.pow(16, power++); } return sum;} And there are 16777216 different colors rather than 64770. Link to comment Share on other sites More sharing options...
PrateekSaxena Posted January 2, 2007 Author Share Posted January 2, 2007 thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now