and as a side note - picking a random color would very easy:
Var myRandomColor = new Color($random(0, 0xFFFFFF));
;)
On Jan 9, 10:15 pm, Sam <[email protected]> wrote:
> function num2rgb(num)
> {
> var r = (num >> 16) & 0xFF;
> var g = (num >> 8) & 0xFF;
> var b = num & 0xFF;
>
> return [r,g,b];
>
> }
>
> This could be use for the number to array conversion, sense hex
> (0xFFFFFF) is just a number.
>
> There is no rgba hex standard that I know of. So I had this wild idea
> of an trgb hex representation.
>
> function num2rgbt(num)
> {
> var t = (num >> 24) & 0xFF;
> var r = (num >> 16) & 0xFF;
> var g = (num >> 8) & 0xFF;
> var b = num & 0xFF;
>
> return [r,g,b,t];
>
> }
>
> t is for transparency. Sense a transparency of 0 is full opacity, when
> you pass a number that doesn't consider the t value (e.g. 0xRRGGBB,
> rather then 0xTTRRGGBB) the value of t would become 0 which is full
> opacity. In order to write trgb hex values you just simply add another
> two hex digits to the hex number: 0xFF998877. The t value would be
> optional and have a range from 0-255, just like r, g, and b.
>
> Just something that came to mind when I was/am writing this message.
>
> Another idea, instead of transparency being at the beginning of the
> hex representation (0xTRGB), what if the transparency was at the end
> (0xRGBT):
>
> function num2rgbt(num)
> {
> if (num > 0x1000000)
> {
> var r = (num >> 24) & 0xFF;
> var g = (num >> 16) & 0xFF;
> var b = (num >> 8) & 0xFF;
> var t = num & 0xFF;
> }
> else
> {
> var r = (num >> 16) & 0xFF;
> var g = (num >> 8) & 0xFF;
> var b = num & 0xFF;
> }
>
> return [r,g,b,t];
>
> }
>
> Works just the same. In fact, with this method you wouldn't be forced
> to use transparency but instead could use alpha or opacity.
>
> function num2rgba(num)
> {
> if (num > 0x1000000)
> {
> var r = (num >> 24) & 0xFF;
> var g = (num >> 16) & 0xFF;
> var b = (num >> 8) & 0xFF;
> var a = num & 0xFF;
> a = t/255;
> }
> else
> {
> var r = (num >> 16) & 0xFF;
> var g = (num >> 8) & 0xFF;
> var b = num & 0xFF;
> }
>
> return [r,g,b,a];
>
> }
>
> Now the alpha value could be either one digit or two! 0xff9988f would
> be 0xff red, 0x99, green, 0x88 blue, and 0x1 or 15 alpha. Of course
> alpha is divided by 255 to make it a value from 0-1 rather then 0-255.
>
> Anyhow, the main reason for this post is to give some tips for the
> developers of Mootools as to how to convert number values to color
> values.
>
> Cheers guys! =D
>
> On Jan 5, 1:45 pm, Sam <[email protected]> wrote:
>
> > 0xff0000 would be easier to type then using string quotes IMO. I see
> > what your saying, when would I ever use the Color class? I guess I
> > wouldn't, but I would use need a way to represent colors in javascript
> > in general. Like when I need to set an elements background or color
> > CSS property. As well as a string, it would be nice to be able to pass
> > numbers to all CSS color properties. So I could write:
>
> > myElement.setStyles({
> > color: 0xff0000,
> > backgroundColor: 0xff0000
>
> > });
>
> > . I'm not saying that we should replace numbers with strings for color
> > values, but just add this to the framework. This way it's up to the
> > developer to decide which he/she prefers.
>
> > On Jan 5, 2:04 am, Michal <[email protected]> wrote:
>
> > > Interesting, but where do you think you would use this class? What
> > > would make it better than just the colour strings '#eeeeee' ?
>
> > > Michal.
>
> > > On Jan 5, 9:20 am, Sam <[email protected]> wrote:
>
> > > > I don't know it's appropriate to suggest things in this group but I'll
> > > > give it a shot.
>
> > > > About the Color class' first parameter, it could be either a string or
> > > > an array. It can be a string of a hex html value, "#ff0000" for
> > > > example. It can also be an array of the rgb or rgba values: [r, g, b,
> > > > a]. These are all good but might I suggest a number value as well?
> > > > Sense javascript has a hex based number syntax you could write
> > > > 0xff0000 and javascript will recognize this as 16711680. This would be
> > > > a great feature to the Color class.
>
> > > > What do you think?