         paths
 
     paths.url = () ->
-      "url(#" + paths.id() + ")"
-        
+      "url(##{id})"
+
     paths
-
-}
root = exports ? this

# helper function
rand = () ->
  (Math.random().toString(36)+"00000000000000000")
    .replace(/[^a-z]+/g, "")
    .slice(0, 5)

# global object
root.textures = {
  
  # circles ------------------------------------------------------------

  circles : () ->

    size = 20
    background = ""
    radius = 2


    path = (orientation) ->
      switch orientation
        when "0/8" then do (s=size) ->
          "M #{s/2}, 0 l 0, #{s}"
        when "vertical" then do (s=size) ->
          "M #{s/2}, 0 l 0, #{s}"
        when "1/8" then do (s=size) ->
          """M #{s/4},0 l #{s/2},#{s} M #{-s/4},0 l #{s/2},#{s}
             M #{s*3/4},0 l #{s/2},#{s}"""
        when "2/8" then do (s=size) ->
          """M 0,#{s} l #{s},#{-s} M #{-s/4},#{s/4} l #{s/2},#{-s/2}
             M #{3/4*s},#{5/4*s} l #{s/2},#{-s/2}"""
        when "diagonal" then do (s=size) ->
          """M 0,#{s} l #{s},#{-s} M #{-s/4},#{s/4} l #{s/2},#{-s/2}
             M #{3/4*s},#{5/4*s} l #{s/2},#{-s/2}"""
        when "3/8" then do (s=size) ->
          """M 0,#{3/4*s} l #{s},#{-s/2} M 0,#{s/4} l #{s},#{-s/2}
             M 0,#{s*5/4} l #{s},#{-s/2}"""
        when "4/8" then do (s=size) ->
          "M 0,#{s/2} l #{s},0"
        when "horizontal" then do (s=size) ->
          "M 0,#{s/2} l #{s},0"
        when "5/8" then do (s=size) ->
          """M 0,#{-s/4} l #{s},#{s/2}M 0,#{s/4} l #{s},#{s/2}
             M 0,#{s*3/4} l #{s},#{s/2}"""
        when "6/8" then do (s=size) ->
          """M 0,0 l #{s},#{s} M #{-s/4},#{3/4*s} l #{s/2},#{s/2}
             M #{s*3/4},#{-s/4} l #{s/2},#{s/2}"""
        when "7/8" then do (s=size) ->
          """M #{-s/4},0 l #{s/2},#{s} M #{s/4},0 l #{s/2},#{s}
             M #{s*3/4},0 l #{s/2},#{s}"""
        else do (s=size) ->
          "M #{s/2}, 0 l 0, #{s}"

    lines = () ->
      g = this.append "defs"
          .append "pattern"
          .attr
            id: id
            patternUnits: "userSpaceOnUse"
            width: size
            height: size
      if background
        g.append "rect"
          .attr
            width: size
            height: size
            fill: background
      for o in orientation
        g.append "path"
          .attr
            d: path o
            "stroke-width": strokeWidth
            "shape-rendering": shapeRendering
            stroke: stroke
            "stroke-linecap": "square"

    lines.background = (_) ->
      background = _
