技术控

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

[其他] Recursive SVG Patterns Part 2

[复制链接]
另一种晚安 发表于 2016-10-5 05:12:52
117 0

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
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
友荐云推荐




上一篇:Matlab 中文用户谨慎更新 macOS Sierra
下一篇:Summarizing Garbage Collection
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表