Built with blockbuilder.org
DS July: Code 1
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: gpl-3.0 |
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> | |
svg { | |
width: 900px; | |
height: 900px; | |
} | |
</style> | |
</head> | |
<body> | |
<svg> | |
</svg> | |
<script> | |
var padding = 20; | |
var svg = d3.select('svg') | |
.append('g') | |
.attr('transform', 'translate(' + [padding, padding] + ')'); | |
// draw petal | |
var petals = [[ | |
'M0,0', | |
// 'C50,10 100,25 100,50', | |
// 'C100,75 75,100 50,100', | |
// 'C25,100 0,75 0,50', | |
// 'C0,25 50,10 50,0' | |
"C50,50 50,100 0,100", | |
"C-50,100 -50,50 0,0" | |
], | |
[ | |
'M-35,0', | |
'C-25,25 25,25 35,0', | |
'C50,25 25,75 0,100', | |
'C-25,75 -50,25 -35,0' | |
], | |
// [ | |
// 'M25,0', | |
// 'C35,0 35,10 50,10', | |
// 'C65,10 65,0 75,0', | |
// 'C100,0 100,100 50,100', | |
// 'C0,100 0,0 25,0' | |
// ], | |
[ | |
'M0,0', | |
'C50,40 50,70 20,100', | |
'L0,85', | |
'L-20,100', | |
'C-50,70 -50,40 0,0' | |
], | |
[ | |
'M0,0', | |
'C50,25 50,75 0,100', | |
'C-50,75 -50,25 0,0' | |
]]; | |
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) * 150; | |
var y = Math.floor(i / 3) * 150; | |
i += 1; | |
return 'translate(' + (150*i) + ',' + 0 + ')'; | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment