var a = 10
var b = minV - 20
context.fillStyle = 'rgb(200,100,100)'
var i = 0
while (i < 20) {
var c1 = (20 - i) * 10
var c2 = "'"+'rgb(' + c1 + ','+ c1 +','+ c1 + ")'"
console.log(c2)
context.setFillStyle = c2
context.fillRect(a + i, a + i, b - i * 2, b - i * 2)
i = i + 1
}
其中倒数第四行 context.setFillStyle = c2,没有起作用,求助。谢谢!
您好,能否提供个可运行的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
看了一下你的代码,有两个问题:
一个是因为你的格式有问题,改成以下代码即可:
var c2 = 'rgb(' + (c1) + ','+ (c1) +','+ (c1) + ")"
另外一个得把setFillStyle方法改成fillStyle,如:
context.fillStyle = c2
var canvas = wx.createCanvas("fore")
var scrw = 0
var scrh = 0
var minV = 0
wx.getSystemInfo
(
{
success: function (res)
{
scrh = res.windowHeight
scrw = res.windowWidth
minV = scrh
if (scrh > scrw)
minV = scrw
}
}
)
canvas.width = minV
canvas.height = minV
// console.log(canvas.width, canvas.height)
var context = canvas.getContext('2d')
var a = 10
var b = minV - 20
context.fillStyle = 'rgb(200,100,100)'
var i = 0
while (i < 20) {
var c1 = (20 - i) * 10
var c2 = "'"+'rgb(' + c1 + ','+ c1 +','+ c1 + ")'"
console.log(c2)
context.setFillStyle = c2
context.fillRect(a + i, a + i, b - i * 2, b - i * 2)
i = i + 1
}
var offScreenCanvas1 = wx.createCanvas()
var offContext1 = offScreenCanvas1.getContext('2d')
offContext1.fillStyle = 'blue'
offContext1.fillRect(0, 0, 100, 100)
context.drawImage(offScreenCanvas1, 100, 100);