Built with blockbuilder.org
Last active
May 22, 2018 05:57
-
-
Save abonello/5495b452fab624d11869af6b2afb1d06 to your computer and use it in GitHub Desktop.
My Petals
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
license: mit |
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { | |
width: 900px; | |
height: 900px; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
<script> | |
//draw petal | |
var petals = [ | |
[ | |
'M0,0', | |
'C50,40 50,70 20,100', | |
'L0,85', | |
'L-20,100', | |
'C-50,70 -50,40 0,0' | |
], | |
[ | |
'M50,0', | |
'C80,30 90,70 75,100', | |
'L50,65', | |
'L25,100', | |
'C10,70 20,30 50,0' | |
] | |
]; | |
d3.select('svg').selectAll('path') | |
.data(petals).enter().append('path') | |
.attr('stroke', '#000') | |
.attr('stroke-width', 2) | |
.attr('fill', 'none') | |
.attr('d', function(d) {return d}) | |
.attr('transform', function(d, i){ | |
var x = (i%3 + 0.5) * 150; | |
var y = (Math.floor(i/3) + 0.5) *150; | |
return `translate(${x}, ${y})`; | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment