rgba fillStyle with alpha does not get fully opaque if applied multiple times

前端 未结 4 1695
一整个雨季
一整个雨季 2020-12-19 05:49

I stubled upon a weird problem. The following code results in making the image fade away because it\'s overdrawn by a semi-opaque rect over and over again.

But at lea

4条回答
  •  余生分开走
    2020-12-19 06:09

    Since the rectangle is only 10% opaque, the result of drawing it over the image is a composite of 90% of the image and 10% white. Each time you draw it you lose 10% of the previous iteration of the image; the rectangle itself does not become more opaque. (To get that effect, you would need to position another object over the image and animate its opacity.) So after 10 iterations you still have (0.9^10) or about 35% of the original image. Note that rounding errors will probably set in after about 30 iterations.

提交回复
热议问题