繁体   English   中英

如何使用HTML5画布绘制具有居中淡出渐变的圆圈?

[英]How to Draw a Circle with Centered Fadeing Out Gradients with HTML5 Canvas?

如何绘制渐弱渐变的圆圈?

我的意思是这样的:

在此输入图像描述

变暗和变暗......

您想使用ctx.createRadialGradient()方法。

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();

示例: http //jsfiddle.net/razh/sA6Wc/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM