How can I draw a circle with fadeing out gradients?
I mean something like this:
Getting darker and darker...
The createRadialGradient() method creates a radial/circular gradient object. The gradient can be used to fill rectangles, circles, lines, text, etc. Tip: Use this object as the value to the strokeStyle or fillStyle properties.
radial-gradient() The radial-gradient() CSS function creates an image consisting of a progressive transition between two or more colors that radiate from an origin. Its shape may be a circle or an ellipse. The function's result is an object of the <gradient> data type, which is a special kind of <image> .
You want to use the ctx.createRadialGradient()
method.
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var x = 100,
y = 75,
// Radii of the white glow.
innerRadius = 5,
outerRadius = 70,
// Radius of the entire circle.
radius = 60;
var gradient = ctx.createRadialGradient(x, y, innerRadius, x, y, outerRadius);
gradient.addColorStop(0, 'white');
gradient.addColorStop(1, 'blue');
ctx.arc(x, y, radius, 0, 2 * Math.PI);
ctx.fillStyle = gradient;
ctx.fill();
Example: http://jsfiddle.net/razh/sA6Wc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With