gpt4 book ai didi

javascript - 如何用HTML5 Canvas绘制居中淡出渐变的圆圈?

转载 作者:技术小花猫 更新时间:2023-10-29 12:47:41 25 4
gpt4 key购买 nike

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

我的意思是这样的:

enter image description here

越来越黑......

最佳答案

您想使用 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/

关于javascript - 如何用HTML5 Canvas绘制居中淡出渐变的圆圈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16494262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com