Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hand drawing (crayon) style for SVG path?

The SVG path usually looks like a solid line:

enter image description here

Is it possible to implement a hand-drawing (crayon) style for SVG path?

enter image description here

like image 253
Hanfei Sun Avatar asked May 14 '15 05:05

Hanfei Sun


2 Answers

You can try something like this using svg's filter

<svg width="1000" height="500">
    <defs>
    <filter id="filter" height="2" width="2">
      <feTurbulence baseFrequency="0.2" numOctaves="3" type="fractalNoise" />
      <feDisplacementMap  scale="80"  xChannelSelector="R" in="SourceGraphic" />
     
    </filter>
    </defs>
    <path d="m 100 100 l 200 10" stroke="black" stroke-width="20" style="filter:url(#filter)"/>
like image 84
Akshay Avatar answered Nov 14 '22 18:11

Akshay


If you don't want the edges clipped and want a more solid stroke, then you can tweak Akshay's settings by setting filterUnits in userSpace and reducing the displacement scale like so:

<svg width="1000" height="500">
    <defs>
    <filter id="filter" filterUnits="userSpaceOnUse" x="-5" y="-5" height="200" width="2000">
      <feTurbulence baseFrequency="0.2" numOctaves="3" type="fractalNoise" />
      <feDisplacementMap  scale="8"  xChannelSelector="R" in="SourceGraphic" />
     
    </filter>
    </defs>
    <path d="m 100 100 l 200 10" stroke="black" stroke-width="20" style="filter:url(#filter)"/>
like image 30
Michael Mullany Avatar answered Nov 14 '22 18:11

Michael Mullany