1 回答
TA贡献1824条经验 获得超8个赞
您必须显式地将变量插入到 rgb 字符串中:
ctx.strokeStyle = "rgb("+a+","+b+","+c+")"
如果支持,您还可以使用模板字符串:
ctx.strokeStyle = `rgb(${a},${b},${c})`
var canvas = document.getElementById("minCanvas");
var ctx = canvas.getContext("2d");
var side=600;
var x=0;
var y=0;
var a = 255;
var b = 255;
var c = 255;
while (side>0) {
ctx.strokeStyle = "rgb("+a+","+b+","+c+")";
ctx.strokeRect(x, y, side, side);
//ctx.stroke();
a-=50;
b-=10;
c-=30;
x+=5;
y+=5;
side-=10;
}
body {
background-color:rgb(30, 30, 30);
color:White;
}
<h2>IDK</h2>
<canvas id="minCanvas" width="600" height="600"></canvas>
添加回答
举报