| Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
| Autor |
Nachricht |
Gast Gast
|
Farbverlauf |
|
|
Hallo,
ich bin auf der suche nach einer Funktion die folgendes leistet:
ich gebe eine Startfarbe und eine Endfarbe an, sowie einen Prozentwert
Als Rückgabewert möchte ich eine Farbe erhalten, die sich um den Prozentwert von der Startfarbe in Richtung der Endfarbe verschoben hat.
so wie auf dieser seite
http://www.homepage-total.de/html/f...be2=D60000&laenge=100
Die Farblänge wäre in diesem Fall 100, weil ich ja mit Prozenten arbeiten möchte. |
|
|
|
| 19 Feb 2010 14:24 |
|
  |
Gast
|
 |
|
|
habe schon was gefunden
/***********************************************
*
* Function : getColor
*
* Parameters : start - the start color (in the form "RRGGBB" e.g. "FF00AC")
* end - the end color (in the form "RRGGBB" e.g. "FF00AC")
* percent - the percent (0-100) of the fade between start & end
*
* returns : color in the form "#RRGGBB" e.g. "#FA13CE"
*
* Description : This is a utility function. Given a start and end color and
* a percentage fade it returns a color in between the 2 colors
*
* Author : www.JavaScript-FX.com
*
*************************************************/
function getColor(start, end, percent)
{
var r1=hex2dec(start.slice(0,2));
var g1=hex2dec(start.slice(2,4));
var b1=hex2dec(start.slice(4,6));
var r2=hex2dec(end.slice(0,2));
var g2=hex2dec(end.slice(2,4));
var b2=hex2dec(end.slice(4,6));
var pc = percent/100;
r= Math.floor(r1+(pc*(r2-r1)) + .5);
g= Math.floor(g1+(pc*(g2-g1)) + .5);
b= Math.floor(b1+(pc*(b2-b1)) + .5);
return("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}
/*** These are the simplest HEX/DEC conversion routines I could come up with ***/
/*** I have seen a lot of fade routines that seem to make this a ***/
/*** very complex task. I am sure somene else must've had this idea ***/
var hexDigit=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
function dec2hex(dec){return(hexDigit[dec>>4]+hexDigit[dec&15]);}
function hex2dec(hex){return(parseInt(hex,16))}
/************************************************/ |
|
|
|
| 19 Feb 2010 14:54 |
|
 |
|