SVGLayer

SVGLayer 可以帮助你创建或者引用代码或设计模式下的 SVG 元素,并设置它们的路径、填充色、描边等等。

svg.svg <string | svg>

svg属性可以直接传入一段完整的 SVG 元素代码。

  1. shape = new SVGLayer
  2. svg: "<svg><rect width='200' height='200' fill='#0AF' />"

当然你也可以通过这个属性去访问 svg 元素。

  1. print shape.svg
  2. # <SVGElement {}>

svg.path <layer>

读取 svg 图形的 path 属性。需要注意的是,只有仅包含一个 path 的图形才可以使用这个属性。

  1. shape = new SVGLayer
  2. svg: "<svg><path d='M0 0 H 200 V 200 H 0 L 0 0' fill='#0AF' />"
  3. print shape.path
  4. # <SVGPathElement {}>

结合 point 属性,你可以让图层沿着一段 SVG 路径运动。

  1. shape = new SVGLayer
  2. svg: "<svg><path d='M0 0 H 200 V 200 H 0 L 0 0' />"
  3. stroke: "#CCC"
  4. layer = new Layer
  5. size: 100
  6. layer.animate
  7. point: shape.path

svg.fill <layer>

设置 SVG 图层的填充色。

  1. shape = new SVGLayer
  2. svg: "<svg><path d='M0 0 H 200 V 200 H 0 L 0 0' />"
  3. fill: "#0AF"

svg.stroke <string>

设置 SVG 图层的描边颜色。

  1. shape = new SVGLayer
  2. svg: "<svg><rect width='200' height='200' />"
  3. stroke: "#0AF"

svg.strokeWidth <number>

你可以使用 strokeWidth 属性调节图形的描边宽度。

  1. shape = new SVGLayer
  2. svg: "<svg><rect width='200' height='200' />"
  3. stroke: "#0AF"
  4. strokeWidth: 10