V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ylsywkd
V2EX  ›  问与答

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

  •  
  •   ylsywkd · Oct 12, 2015 · 2098 views
    This topic created in 3856 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   ·   806 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    ♥ Do have faith in what you're doing.