Created
September 5, 2017 13:27
-
-
Save dontpaniclabsgists/6b669a61b17f00dba9dd1d1be0786ea3 to your computer and use it in GitHub Desktop.
print_graphic_2
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 stars = 600;sk | |
var sizeVariance = .9; var starSize = 2.5; | |
var opacityVariance = 1; var w = 2100; | |
var h = 650; | |
var g = document.getElementById("group"); | |
for (var i = 0 ; i < stars ; i++){ | |
var x = getRandomNumber(0,w); | |
var y = getRandomNumber(0,h); | |
var r = getRandomNumber((starSize - (starSize*sizeVariance)),(starSize + (starSize*sizeVariance))); | |
var o = getRandomNumber((1 - opacityVariance),1); g.append(makeStar(x,y,r,o)); | |
} | |
function makeStar(x,y,r,o){ | |
var s = document.createElementNS("http://www.w3.org/2000/svg", "circle"); s.setAttribute("cx",x); | |
s.setAttribute("cy",y); | |
s.setAttribute("r",r); | |
} | |
function makeStar(x,y,r,o){ | |
var s = document.createElementNS("http://www.w3.org/2000/svg", "circle"); s.setAttribute("cx",x); | |
s.setAttribute("cy",y); | |
s.setAttribute("r",r); | |
s.setAttribute("fill","#FFFFFF"); s.setAttribute("fill-opacity",o); return s; | |
} | |
function getRandomNumber(min,max){ | |
var dist = max - min; | |
return min + (Math.random()*dist); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks this came in pretty handy for a similar need I had.
As an FYI, on line one you have some rogue characters on the end "sk", and you also have two makeStar functions when only the second is required so you can get rid of the first one completely.