我想知道是否可能通过函数调用
更改Canvas
颜色? 我有一个带有圆形的代码块,我想更改外围颜色(背景):
var canvads = document.getElementById('canvas')
var context = canvas.getContext('2d');
function circle() {
var centerX = 0;
var centerY = 0;
var radius = 78;
context.clearRect(0, 0, window.innerWidth,window.innerHeight);
context.fillStyle = 'rgba(0,0,0,0.5)';
context.fillRect(0,0,window.innerWidth,window.innerHeight);
context.translate(canvas.width / 2, canvas.height / 2);
context.scale(1.5, 2);
context.beginPath();
context.arc(centerX, centerY, radius, 0, 5 * Math.PI, false);
context.lineWidth = 5;
context.stroke();
context.fillStyle = 'rgba(0,0,0,1)';
context.globalCompositeOperation = 'destination-out';
context.fill();
context.globalCompositeOperation = 'source-over';
}
function change_color() {
context.fillStyle = 'rgba(0,255,0,1)';
context.fill();
}
circle()