请选择 进入手机版 | 继续访问电脑版

技术控

    今日:0| 主题:62019
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Recursive SVG Patterns Part 2

[复制链接]
另一种晚安 发表于 2016-10-5 05:12:52
140 0
In the    previous SVG patterns article, I demonstrated how to build an illustration recursively, using a single element. This next version is more complex, demonstrating how to build patterns from nested, referencedgroups.  
  The entire pattern is built from a singlepolygon:  
  1. <svg version="1.1" xmlns="http://www.w3.org/2000/svg"
  2.     xmlns:xlink="http://www.w3.org/1999/xlink"
  3.         viewBox="0 0 562.6" 325">
  4.     <polygon id="base" points="281.4,0 375.2, 162.5 281.4, 325 187, 161.5" />
  5. </svg>
复制代码
The design has some basicCSS applied:  
  1. polygon {
  2.     fill: none;
  3.     stroke: rgba(0,0,0,0.3);
  4.     stroke-width: 3;
  5. }
复制代码
Due to the fact thatstrokes scale in thickness in their associated elements, thergba color will help create lighter copies.  
  The “base” polygon element is at the root of an extended group of elements:
  1. <g id="group">
  2.     <polygon points="281.4,0 375.2, 162.5 281.4, 325 187, 161.5"
  3.     id="base" />
复制代码
Each variant of the original polygon is referenced via an          xlink    , and provided with its own          id    , becoming the template for further variants, inside its own group:  
  1. <g id="group">
  2.     <polygon points="281.4,0 375.2, 162.5 281.4, 325 187, 161.5" id="base" />
  3.         <g id="basetwist" >
  4.             <use xlink:href="#base" transform="rotate(90 280 162.5) translate(116, 67) scale(.58)" id="base_level1" />
复制代码
The full pattern:
  1. <g id="group">
  2.     <polygon points="281.4,0 375.2, 162.5 281.4, 325 187, 161.5" id="base" />
  3.         <g id="basetwist" >
  4.             <use xlink:href="#base" transform="rotate(90 280 162.5) translate(116, 67) scale(.58)" id="base_level1" />
  5.             <g id="diamond">
  6.                 <use xlink:href="#base" transform="translate(188.85, 108) scale(.33)" id="base_level2" />
  7.                 <g id="sidediamond">
  8.                     <use xlink:href="#base_level1" transform="translate(188.85, 108) scale(.33)" id="base_level3" />
  9.                     <use xlink:href="#base_level2" transform="translate(188.85, 108) scale(.33)" id="base_level4" />
  10.                     <use xlink:href="#base_level3" transform="translate(188.85, 108) scale(.33)" />
  11.                     <use xlink:href="#base_level4" transform="translate(188.85, 108) scale(.33)" />
  12.                 </g>
  13.             </g>
  14.         <use xlink:href="#sidediamond" transform="translate(62,0)" />
  15.         <use xlink:href="#sidediamond" transform="translate(-62,0)" />
  16.         <use xlink:href="#diamond" transform="translate(0,-107)" />
  17.         <use xlink:href="#diamond" transform="translate(0, 107)" />
  18.     </g>
  19. </g>
复制代码
Note the the    #base_levelelements are true recursions: each element uses the previous version, and uses the same    transformand    translatevalues to create smaller copies.  
  Creating the full design means referencing what has been built up so far as a single group, still working inside the    <pattern>. First, we create multiple copies of the pattern, rotated from the top and bottom points of the original shape:  
  1. <g id="tesselation">
  2.     <use xlink:href="#group" />
  3.     <use xlink:href="#group" transform="rotate(60 281 0)" />
  4.     <use xlink:href="#group" transform="rotate(-60 281 0)" />
  5.     <use xlink:href="#group" transform="rotate(-60 281 325)" />
  6.     <use xlink:href="#group" transform="rotate(60 281 325)" />
  7.     …
  8. </g>
复制代码
Still inside this group, further translated copies are made:
  1. <g id="vert">
  2.         <use xlink:href="#group" transform="translate(-282, -162)" />
  3.         <use xlink:href="#group" transform="translate(-282, 162)" />
  4.     </g>
  5.     <use xlink:href="#vert" transform="translate(564, 0)" />
复制代码
Using the pattern

  Using the pattern in a page involves creating a rectangle and filling it with the final, complete pattern:
  1. <rect width="100%" height="100%" fill="url(#tesselation)" />
复制代码
You can also find    the complete pattern and code on CodePen.  
  Enjoy this piece? I invite you to follow me at    twitter.com/dudleystoreyto learn more.   
Check out the CodePen demo for this article at    https://codepen.io/dudleystorey/pen/pEWdmG
我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/c.CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表