ylsywkd
V2EX  ›  问与答

html canvas 元素的绘图操作是异步的吗?

  •  
  •   ylsywkd · Oct 12, 2015 · 2173 views
    This topic created in 3886 days ago, the information mentioned may be changed or developed.


    var ctx = canvas.getContext('2d');
    for (var i = 0; i < canvas.height; i++) {
    for (var j = 0; j < canvas.width; j++) {
    var r1 = Math.round(Math.random() * 255),
    r2 = Math.round(Math.random() * 255),
    r3 = Math.round(Math.random() * 255);
    ctx.fillStyle = 'rgba(' + r1 + ',' + r2 + ',' + r3 + ',' + '1' + ')';
    ctx.fillRect(j, i, 1, 1);
    }
    }

    图像是一下子渲染出来的,而不是一个个像素出现的。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1240 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:47 · PVG 01:47 · LAX 10:47 · JFK 13:47
    ♥ Do have faith in what you're doing.