ylsywkd
V2EX  ›  问与答

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

  •  
  •   ylsywkd · Oct 12, 2015 · 2154 views
    This topic created in 3880 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   ·   5289 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 07:45 · PVG 15:45 · LAX 00:45 · JFK 03:45
    ♥ Do have faith in what you're doing.