You are here: Re: Mozilla color question « HTML « IT news, forums, messages
Re: Mozilla color question

Posted by cwdjrxyz on 11/22/06 16:44

Toby Inkster wrote:
> cwdjrxyz wrote:
>
> > function MakeArray(n){
> > this.length=n;
> > for(var i=1; n>=i; i++) this[i]=i-1;
> > return this
> > }
> >
> > hex=new MakeArray(16);
> > hex[11]="A"; hex[12]="B"; hex[13]="C"; hex[14]="D"; hex[15]="E";
> > hex[16]="F";
> >
> > function ToHex(x){ // Changes a int to hex (in the range 0
> > to 255)
> > var high=x/16;
> > var s=high+""; //1
> > s=s.substring(0,2); //2 the combination of these are the
> > same as the trunc function
> > high=parseInt(s,10); //3
> > var left=hex[high+1]; // left part of the hex-value
> > var low=x-high*16; // calculate the rest of the values
> > s=low+""; //1
> > s=s.substring(0,2); //2 the combination of these are the
> > same as the trunc function
> > low=parseInt(s,10); //3
> > var right=hex[low+1]; // right part of the hex-value
> > var string=left+""+right; // add the high and low together
> > return string;
> > }
>
> You base your entire argument on the "fact" that converting from decimal
> to hexadecimal in Javascript is hard. It's not.

No, I base my argument on the fact that converting from decimal to
hexadecimal is not needed at all if you use the r,g,b notation. Other
applications may not be quite as simple as the very simple example used
here. It is somewhat like selecting the "natural" coordinate system for
math calculations. For example, it is sometimes fairly simple to
calculate functions that involve a circle or sphere with ordinary
cartesian coordinates. However using the natural coordinates for a
circle, polar coordinates, often makes the equations more
compact,elegant, and easier to handle. Of course the old 1996 script
likely used a more complicated hex/decimal conversion than was needed
for the simple problem; however I do not know enough about the status
of script and html in 1996 to know for sure if this was the case.

>
> var r = 196; // red value in decimal
> var g = 128; // green value in decimal
> var b = 255; // blue value in decimal
> var total = (256*256*r) + (256*g) + b; // combine
> var hexcolour = "#" + total.toString(16); // ToHex
>
> Your rainbow script, using hexadecimal notation is:
>
> function paint(blah)
> {
> c1=255; x=blah.length; f=c1/x; c0=255;
> for (i=0;x>i;i++)
> {
> c1=Math.round(255*Math.sin(i/(x/3)));
> c2=Math.round(f*i);
> total = (256*256*c0) + (256*c1) + c2;
> hexcolour = "#" + total.toString(16);
> document.write('<span style="color:' + hexcolour + '">'
> + blah.substring(i,i+1) + '<\/span>');
> }
> }
>
> Easy.
>
> --
> Toby A Inkster BSc (Hons) ARCS
> Contact Me ~ http://tobyinkster.co.uk/contact

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация