Form
context.createRadialGradient(startX,startY,startR,endX,endY,endR)
Parameters
parameter |
description |
startX |
specifies the X coordinate of the start of the gradient |
startY |
specifies the Y coordinate of the start of the gradient |
startR |
specifies the radius of the start circle |
endX |
specifies the X coordinate of the end of the gradient |
endY |
specifies the Y coordinate of the end of the gradient |
endR |
specifies the radius of the end circle |
Explanation
The createRadialGradient creates a radial gradient. The gradient is created by two pairs of coordinates from (x1,y1) to (x2,y2). This is just a circular, so specify the radius for the start circle and the end one. Set your specified gradient to the fillStyle, etc. for actually drawing. And then, draw a graphic.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=shift_jis">
<title>Sample</title>
<script type="text/javascript"><!--
function drawPoint()
{
canvasObj = document.getElementById("imgCanvas");
conObj = canvasObj.getContext("2d");
gradObj = conObj.createRadialGradient(160,120,0, 160,120,200);
gradObj.addColorStop(0, "#ff0000");
gradObj.addColorStop(1, "#0000ff");
conObj.fillStyle = gradObj;
conObj.rect(10,10,300,220);
conObj.fill();
}
// --></script>
</head>
<body onload="drawPoint()">
<h1>Sample</h1>
<canvas id="imgCanvas" width="320" height="240" style="border:1px black solid"></canvas>
</body>
</html>