var element = evt.target; var poly = element.shadowTree; var path = poly.getElementById("drawing_arc"); // get attributes from custom tag var cx = 0, cy = 0, r = 0, start = 0, sides = 0, cross = 1, units="degrees" nb_attributes = element.attributes.length for (i = 0; i < nb_attributes;i++) { attribute = element.attributes.item(i) switch(attribute.name) {case "cx" : cx = attribute.value - 0 ; break; case "cy" : cy = attribute.value - 0 ; break; case "r" : r = attribute.value - 0 ; break; case "start" : start = attribute.value - 0 ; break; case "sides" : sides = attribute.value - 0 ; break; case "cross" : cross = attribute.value - 0 ; break; case "units" : units = attribute.value ; break; case "onclick" : break; case "onmousedown" : break; case "onmousemove" : break; case "onmouseup" : break; case "onmousein" : break; case "onmouseout" : break; case "id" : break; case "cursor" : break; default : path.setAttributeNS(null, attribute.name, attribute.value) } } if (units == "degrees") start = start * Math.PI / 180 if (start < 0) start = start + 2 * Math.PI // calculate d attribute for path var x_begin = cx + r * Math.cos(start); var y_begin = cy + r * Math.sin(start); var angle = 2 * Math.PI / sides var string_d = "M" + x_begin.toString() + " " + y_begin.toString() var start_angle = start + angle * cross while (Math.abs(start_angle - start) > 0.1 ) { x_current = cx + r * Math.cos(start_angle); y_current = cy + r * Math.sin(start_angle); string_d += "L" + x_current.toString() + " " + y_current.toString() start_angle = start_angle + angle * cross if (start_angle >= 2 * Math.PI - 0.1) start_angle = start_angle - 2 * Math.PI } string_d += "z" // apply attributes path.setAttributeNS(null, "d", string_d); // add child ( as animate ) if (element.hasChildNodes) { var number_childs = element.childNodes.length for (i = 0; i < number_childs; i++) if (element.childNodes.item(i) != null) { path.appendChild(element.childNodes.item(i).cloneNode("true")) } }