Gradient
Flowing from one color to the other, taking the percentage of red, green and blue for each point.
function BzgGradient(colorA, colorB) {
this.colorA = colorA;
this.colorB = colorB;
this.rA = (colorA >> 16) & 255;
this.gA = (colorA >> 8) & 255;
this.bA = colorA & 255;
this.rB = (colorB >> 16) & 255;
this.gB = (colorB >> 8) & 255;
this.bB = colorB & 255;
this.colorAt = function(perc) {
return
Math.round(perc * this.rA + (1 - perc) * this.rB) << 16 |
Math.round(perc * this.gA + (1 - perc) * this.gB) << 8 |
Math.round(perc * this.bA + (1 - perc) * this.bB);
}
this.draw = function() {
var i, color, width = 900;
document.write('<div class="gradient">');
for (i = 0; i < width; i++) {
color = this.colorAt(i / (width - 1)).toString(16);
while (color.length < 6) color = '0' + color;
document.write('<div class="bar" style="background: #' + color + ';"></div>');
}
document.write('</div>');
}
}