Created
May 9, 2017 07:55
-
-
Save MaxArt2501/3bc85a4c46cce356bc40e5e7664f8b7a to your computer and use it in GitHub Desktop.
How to create a conic gradient in SVG (needs JavaScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From this old post: http://stackoverflow.com/questions/17149286/svg-polar-gradients