Simple fill pattern in svg : diagonal hatching

后端 未结 11 1863
轮回少年
轮回少年 2020-12-04 08:28

How would I fill an SVG shape, not with a single colour, an image or a gradient, but with a hatching pattern, diagonal if possible.

It\'s been 2 hours and I\'ve foun

11条回答
  •  青春惊慌失措
    2020-12-04 09:00

    I've adapted Ingo's answer here.

    
        
            
            
            
            
        
    
    

    This pattern includes two paths, one for the background, and other for the hatches. The background color is addressable vs JS such as:

    const hatchPath = document.querySelector("path#hatches");

    hatchPath.setAttribute('style', "stroke:blue; stroke-width:1")

    The background path is overly-wide on purpose, so that there's no part of the pattern not at least covered by the background. Meanwhile, the hatches can have their width tuned to change how thick the lines are.

提交回复
热议问题