[ Launch: stars ] 6444326 by georules
-
-
Save georules/6444326 to your computer and use it in GitHub Desktop.
stars
This file contains 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
{"description":"stars","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/2hzPczu.png"} |
This file contains 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 svg = d3.select('svg'); | |
var drawLine = function(x1,y1,x2,y2) { | |
svg.append("svg:line") | |
.attr('x1',x1) | |
.attr('x2',x2) | |
.attr('y1',y1) | |
.attr('y2',y2) | |
.style('stroke',"#B99333").style('stroke-width',17) | |
} | |
var drawPoint = function(x,y) { | |
svg.append("svg:circle") | |
.attr('cx',x) | |
.attr('cy',y) | |
.attr('r',10) | |
.style('fill',"#997430").style('stroke-width',22) | |
} | |
var makeStar = function(x1,y1,n) { | |
s = 136 | |
sinner = s/2 | |
centerX = x1; | |
centerY = y1; | |
degreeNext = 2*(Math.PI) / n | |
x1 = centerX | |
x2 = x1 + s | |
y2 = y1 + s | |
drawPoint(centerX,centerY) | |
points = []//[{x:centerX,y:centerY}] | |
degree = 0 | |
// determine the points | |
for (i = 0; i < n; i++) { | |
xn = centerX + s * Math.cos(degree) | |
yn = centerY + s * Math.sin(degree) | |
drawPoint(xn,yn) | |
degree = degree + degreeNext; | |
points.push({x:xn,y:yn}) | |
} | |
// draw the lines, connecting every other point | |
for (i = 0; i < points.length; i++) { | |
var index = i; | |
var index2 = i; | |
if (i >= points.length -2) { | |
index = i; | |
index2 = i-n; | |
} | |
drawLine(points[index].x,points[index].y,points[index2+2].x,points[index2+2].y) | |
} | |
} | |
// make more stars :) | |
makeStar(337,187,6); | |
makeStar(195,530,7); | |
makeStar(510,530,5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment