Skip to content

Instantly share code, notes, and snippets.

@MaxArt2501
Created May 9, 2017 07:55
Show Gist options
  • Save MaxArt2501/3bc85a4c46cce356bc40e5e7664f8b7a to your computer and use it in GitHub Desktop.
Save MaxArt2501/3bc85a4c46cce356bc40e5e7664f8b7a to your computer and use it in GitHub Desktop.
How to create a conic gradient in SVG (needs JavaScript)
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="0 0 100 100" version="1.1" onload="makeGradient();">
<script>
function makeGradient() {
var root = document.rootElement;
var i = 256;
var circle;
var angle;
for (; i--;) {
angle = i * Math.PI / 128;
circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("cx", 50 - Math.sin(angle) * 45);
circle.setAttribute("cy", 50 - Math.cos(angle) * 45);
circle.setAttribute("r", "5");
circle.setAttribute("fill", "rgb(" + i + ", " + i + ", " + i + ")");
root.appendChild(circle);
}
}
</script>
</svg>
@MaxArt2501
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment