Home  >  Article  >  Web Front-end  >  Use HTML5 SVG to draw various snowflake patterns

Use HTML5 SVG to draw various snowflake patterns

青灯夜游
青灯夜游Original
2021-08-31 13:19:082559browse

In the previous article, we introduced the method of using HTML5 CSS3 to dynamically draw a smiley face. If you are interested, you can click on the link to read → "How to use HTML5 CSS3 to dynamically draw a smiling face". This time we continue to talk about using HTML5 SVG to draw patterns.

The main content of today’s article is: using HTML5 svg to draw various snowflake patterns.

First of all, let’s understand what svg is?

SVG is the abbreviation of Scalable Vector Graphics. It is a graphics format in which shapes are specified in XML. The XML is then rendered by the SVG viewer. Today, most web browsers can display SVG just like they can display PNG, GIF, and JPG. SVG is used for two-dimensional vector graphics.

SVG images are created using various elements that are applied to the structure, drawing, and layout of vector images. If svg is not the root element, the svg element can be used to nest a separate svg fragment within the current document (for example, an HTML document). This independent fragment has its own viewport and coordinate system.

Let’s take a look at how to draw various snowflake patterns using HTML5 SVG.

First set the background color of the entire page, the size of the svg canvas, the color of the lines,

body {
  background: #222;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-around;
}
svg {
  width: 25vmin;
  height: 25vmin;
}
.stroke {
  fill: none;
  stroke: #fff;
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

Then start using svg to draw various snowflake patterns

  • Define the svg tag, create the root element of the SVG image, and nest an independent svg fragment within the current document; then use multiple tags to draw the pattern path

  • The first snowflake pattern


  
  
  
  
  
  
  
  

Use HTML5 SVG to draw various snowflake patterns

##The more complex the pattern, the more tags required The more

  • The second snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The third Snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The fourth snowflake pattern

  • 
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The fifth type of snowflake pattern

  • 
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The sixth type of snowflake Pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The seventh snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The eighth snowflake pattern

  • 
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The ninth snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The tenth snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

Use HTML5 SVG to draw various snowflake patterns

  • The eleventh kind of snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
    

1Use HTML5 SVG to draw various snowflake patterns

  • The twelfth kind of snowflake Pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
    

1Use HTML5 SVG to draw various snowflake patterns

  • The Thirteenth Snowflake Pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

1Use HTML5 SVG to draw various snowflake patterns

  • Fourteenth Snowflake Pattern

  • 
      
      
      
      
      
      
      
      
    

1Use HTML5 SVG to draw various snowflake patterns

  • Fifteenth Kind of snowflake pattern

  • 
      
      
      
      
      
      
      
      
      
      
      
      
    

1Use HTML5 SVG to draw various snowflake patterns

  • Sixteenth kind of snowflake pattern

  • 
      
      
      
      
      
      
      
      
    

1Use HTML5 SVG to draw various snowflake patterns

  • The seventeenth snowflake pattern


  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

1Use HTML5 SVG to draw various snowflake patterns

  • 第十八种雪花图案


  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

1Use HTML5 SVG to draw various snowflake patterns

大家可以直接复制以上代码,在本地进行运行演示。

这里给大家介绍几个关键的标签和属性:

  • 元素

SVG 图像是使用各种元素创建的,这些元素分别应用于矢量图像的结构、绘制与布局。如果svg不是根元素,svg 元素可以用于在当前文档(比如说,一个HTML文档)内嵌套一个独立的svg片段 。 这个独立片段拥有独立的视口和坐标系统。

所有SVG图像的根元素都是 元素。


  
  • 路径

path元素是用来定义形状的通用元素。所有的基本形状都可以用path元素来创建。SVG 元素用于绘制由直线,圆弧,曲线等组合而成的高级形状,带或不带填充。该 元素可能是所有元素中最先进,最通用的SVG形状。它可能也是最难掌握的元素。

所有带有元素的绘图都在d属性中指定。 d属性包含绘图命令。

d属性中的第一个绘图命令应该始终是move命令。在你可以画任何东西之前,你应该把虚拟笔移到某个地方。这是使用M命令完成的。

PHP中文网平台有非常多的视频教学资源,欢迎大家学习《HTML视频教程》!

The above is the detailed content of Use HTML5 SVG to draw various snowflake patterns. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn