Drawing GOOD LOOKING (like in Flash) lines on canvas (HTML5) - possible?

后端 未结 3 2142
抹茶落季
抹茶落季 2020-12-10 14:01

Is there any way to draw a line using javascript and the canvas with \"better\" antialiasing, like Flash does?

I know the Math.floor(coord)+0.5 trick to get an exact

相关标签:
3条回答
  • 2020-12-10 14:25

    Leeching off Marius's answer:

    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
       "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    
    <svg width="100%" height="100%" version="1.1"
          xmlns="http://www.w3.org/2000/svg">
    
    <rect width="100" height="50" y="37"
    style="fill:none;stroke-width:1;
    stroke:rgb(0,0,0)"/>
    
    <rect width="100" height="50" x="200"
       style="fill:none;stroke-width:1;
       stroke:rgb(0,0,0)"/>
    
    <line x1="50" y1="67" x2="250" y2="25"
       style="stroke:rgb(0,0,255);stroke-width:2"/>
    
    <text x="2" y="50" >Beta</text>
    <text x="201" y="13" >Omega</text>
    
    </svg>
    

    alt text

    SVG can be drawn client side with javascript, since it's just DOM elements. And, going forward, it is hardware accelerated.

    0 讨论(0)
  • 2020-12-10 14:35

    I doubt you are going to find anything that will make it look truly good that isn't too slow to be useful. One thing that you can try that won't hurt performance too much is to draw 4 lines overlaid on one another, each offset by a fraction of a pixel in x and y. The downside is it will look a bit blurry.

    0 讨论(0)
  • 2020-12-10 14:36

    Instead of using the 2D drawing API, you can use the SVG vector elements. You would have to implement your own api to do it, but that way you will get beautiful lines, like those in flash. The SVG-edit is an example of what you can do with SVN in browser.

    0 讨论(0)
提交回复
热议问题