Jump to content

Color picker...


PrateekSaxena

Recommended Posts

Hello,I am trying to make a color picker in JavaScript. This is how the photoshop and the MSPaint color picker looks-

pscolorpicker.PNGPhotoShop 7colorpickerms.PNGMS 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

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

thanks

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...