Skip to content

Instantly share code, notes, and snippets.

@lexich
Last active December 9, 2016 08:35
Show Gist options
  • Save lexich/97d681f219671f9756220d57e247047a to your computer and use it in GitHub Desktop.
Save lexich/97d681f219671f9756220d57e247047a to your computer and use it in GitHub Desktop.
Draw svg ellipse with path
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Document</title>
</head>
<body>
<svg width="1000" height="1000" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" style="top: 0px; left: 0px; position: relative;">
<g id="SvgjsG1120" transform="matrix(1,0,0,1,0,0)">
<path id="path" id="SvgjsPath1121" d="" stroke="black" fill="red" stroke-width="1" ></path>
</g>
</svg>
<script type="text/javascript">
(function(){
window.el = document.getElementById("path");
const x0 = 0;
const x1 = 500;
const x2 = 1000;
const y0 = 100;
const y1 = 200;
const y2 = 300;
const top = `${x1} ${y0}`;
const middle = `${x1} ${y1}`;
const bottom = `${x1} ${y2}`;
const left = `${x0} ${y1}`;
const right = `${x2} ${y1}`;
const d = `M ${left} ` +
`C ${left} ${x0} ${y0} ${top} ` +
`C ${top} ${x2} ${y0} ${right} ` +
`C ${right} ${x2} ${y2} ${bottom} ` +
`C ${bottom} ${x0} ${y2} ${left} ` +
`Z`;
window.el.setAttribute('d', d);
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment