Implementing smooth sketching and drawing on the element

前端 未结 7 576
粉色の甜心
粉色の甜心 2021-01-29 20:20

I am trying to create a drawing area with canvas. I am having trouble with making the lines look smooth when drawing curves and I also have changing line thickness in my algorit

7条回答
  •  终归单人心
    2021-01-29 20:57

    I made something like this a while ago and turned it into a jquery plugin. have a look over here, if it's what you're after I'll post a more detailed answer and dig out the simplified jquery version from my archives:

    http://jsfiddle.net/95tft/

    EDIT

    OK, sorry I couldn't do this yesterday:

    Originally the code above was forked from Mr Doob's 'harmony' sketcher over here: http://mrdoob.com/projects/harmony/#ribbon

    (which I think is the best solution). But I kinda broke it down and remade it for my own purposes on another project. I've hacked my own plugin a bit to make it a bit easier still over here:

    http://jsfiddle.net/dh3bj/

    The only thing you might want to change is to change it to work on mousedown/mouseup which should be easy also have a look at the settings at the bottom of the plugin, you should be able to get the effect you want by playing with the brush size, colour, alpha (rgba) etc.

    Hope that helps

提交回复
热议问题