Created
February 23, 2015 21:58
-
-
Save ear1grey/78b0be9e301e94f3de3d to your computer and use it in GitHub Desktop.
Static stars, in SVG, added to any page with `<script src="stars.js"></script>`, because, well, stars of course.
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
var rdfx = rdfx || {}; | |
rdfx.stars = function() { | |
var | |
c, | |
svg, | |
ns = "http://www.w3.org/2000/svg", | |
cols = [ | |
"#fff", "#777", "#333", "#333", | |
"#222", "#222", "#222", "#111", | |
"#111", "#111", "#111", "#111" | |
], | |
random = function(s) { | |
return Math.random()*s; | |
}, | |
s = function(i, size) { | |
svg = document.createElementNS(ns, "svg"); | |
svg.setAttributeNS(null, "width", size); | |
svg.setAttributeNS(null, "height", size); | |
svg.setAttributeNS(null, "viewBox", "0 0 2000 2000"); | |
svg.setAttributeNS(null, "preserveAspectRatio", "xMinYMin slice"); | |
svg.setAttributeNS(null, "style", "position: absolute; top:0; left:0; width: 100%; padding: 0; margin: 0;"); | |
document.body.insertBefore(svg, document.body.firstChild); | |
while (i) { | |
i--; | |
c = document.createElementNS(ns, "circle"); | |
c.setAttributeNS(null, "fill", cols[Math.floor(random(9))]); | |
c.setAttributeNS(null, "cx", random(2000)); | |
c.setAttributeNS(null, "cy", random(2000)); | |
c.setAttributeNS(null, "r", random(1.5)); | |
svg.appendChild(c); | |
} | |
} | |
s(10000, 2000); | |
} | |
window.addEventListener("load", rdfx.stars); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment