Add flaglike waving to 2d Context

前端 未结 2 1883
野性不改
野性不改 2021-01-21 21:37

I want to make a function that displays a 2d context in a different way than usual. Sort of like the transform works. Instead of curving/changing the size of the context I want

2条回答
  •  失恋的感觉
    2021-01-21 22:08

    You can use context.drawImage to draw 1 pixel wide vertical slices with a "wavy" y-offset.

    This method gives good performance because you're drawing the entire height of the image at once instead of pixel-by-pixel. Also, the drawing process is much faster than pixel manipulation because the required pixels are blitted from the image to the canvas. And this method uses GPU acceleration when a GPU is available.

    enter image description here

    Example code and a Demo: http://jsfiddle.net/m1erickson/bcjmxr80/

    
    
    
     
    
    
    
    
    
        

    Original Image


    Wavy using vertical slices in canvas

提交回复
热议问题