Efficient javascript equivalent of Processing functions

隐身守侯 提交于 2019-12-08 03:01:25

You can use John Resig's Processing.js for a one shot conversion: http://processingjs.org/

Canvas and JS works is a bit more low level maybe start here : http://net.tutsplus.com/tutorials/javascript-ajax/canvas-from-scratch-pixel-manipulation/

Cris Stringfellow

I've implemented these functions so far with s pointing to a HTMLCanvasElement. Jury is still out on whether arrayCopy can be improved without loop unrolling:

    var x = s.getContext('2d');
    var pixels;
    function arrayCopy(src,sstart,dst,dstart,length) {
            length += sstart;
            dstart += length;
            while(--length > sstart) {
                    dst[--dstart] = src[length];    
            }       
    }
    function loadPixels() {
            pixels = x.getImageData(0,0,s.width,s.height);
    }
    function updatePixels() {
            x.putImageData(0,0,pixels);
    }

I'm still unsure about how to make the JS equivalent of a draw() function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!