By winter Olympics exclusive snowflakes (come! Get your own winter Olympics snowflake (xinhuaxmt.com)) inspired, I also implemented a similar snowflake generation program. Below is the snowflake generated by my code, with some differences from the original. I guess the original version is similar to paper-cut operation, mirror and copy on the bitmap to generate snowflakes. The implementation here generates SVG by directly generating the same pattern on each branch of the snowflake. Color matching is based on the random generation of colors from Zhongguose.com.

The generation process is relatively simple: the position of the snowflake pattern is fixed as shown below, and the size and pattern are randomly generated. And the size of the generated pattern gradually decreases as the pattern moves away from the center of the snowflake. The pattern consists of a circle and a pattern formed by the intersection of two circles or a hexagon and a diamond. Generate the same pattern of the same size and color at the same location on each branch of the snowflake.

Fixed the seed of the random number generator to generate a unique snowflake pattern.

<html>
  <body>
    <snowflake-svg width="100" height="100" seed="9036"></snowflake-svg>
  </body>
  <script src="script/snowflake.js"></script>
</html>
Copy the code

Snowflake generation code: e1y4r/snowflake. Js (github.com)