function
getAngleColor(angle) {
var
color, d;
if
(angle < Math.PI * 2 / 5) {
d = 255 / (Math.PI * 2 / 5) * angle;
color = '255,' + Math.
round
(d) + ',0';
}
else
if
(angle < Math.PI * 4 / 5) {
d = 255 / (Math.PI * 2 / 5) * (angle - Math.PI * 2 / 5);
color = (255 - Math.
round
(d)) + ',255,0';
}
else
if
(angle < Math.PI * 6 / 5) {
d = 255 / (Math.PI * 2 / 5) * (angle - Math.PI * 4 / 5);
color = '0,255,' + Math.
round
(d);
}
else
if
(angle < Math.PI * 8 / 5) {
d = 255 / (Math.PI * 2 / 5) * (angle - Math.PI * 6 / 5);
color = '0,'+(255 - Math.
round
(d)) + ',255';
}
else
{
d = 255 / (Math.PI * 2 / 5) * (angle - Math.PI * 8 / 5);
color = Math.
round
(d) + ',0,' + (255 - Math.
round
(d)) ;
}
return
color;
}
var
iSectors = 360;
var
iSectorAngle = (360 / iSectors) / 180 * Math.PI;
function
drawGradient() {
var
canvas = document.getElementById('gradient');
var
ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
for
(
var
i = 0; i < iSectors; i++) {
var
startAngle = 0;
var
endAngle = startAngle + iSectorAngle;
var
radius = (canvas.width / 2) - 1;
var
color = getAngleColor(iSectorAngle * i);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.arc(0, 0, radius, startAngle, endAngle, false);
ctx.closePath();
ctx.strokeStyle = 'rgb('+color+')';
ctx.stroke();
ctx.fillStyle = 'rgb('+color+')';
ctx.fill();
ctx.rotate(iSectorAngle);
}
ctx.restore();
}
if
(window.attachEvent) {
window.attachEvent('onload', drawGradient);
}
else
{
if
(window.onload) {
var
curronload = window.onload;
var
newonload =
function
() {
curronload();
drawGradient();
};
window.onload = newonload;
}
else
{
window.onload = drawGradient;
}
}