Built with blockbuilder.org
forked from sxywu's block: DS July: Code 1
forked from sxywu's block: Film Flowers Petal Starter Code
forked from anonymous's block: Film Flowers Petal Starter Code
xxxxxxxxxx
<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>
// draw petal
var petals = [
[
'M50,0',
'C80,30 90,70 75,100',
'L50,65',
'L25,100',
'C10,70, 10,30,50, 0'
],
[
'M50,0',
'C90,30 90,70 75,100',
'C70, 70, 30, 70, 25, 100',
'C10,70, 0,30,50, 0'
],
[
'M50,0',
'C50,10 50,30 70,40',
'C70, 70, 30, 70, 25, 100',
'C10,70, 0,30,50, 0'
],
[
'M50,0',
'C100,30 100,70 50,100',
'C0,70, 0,30,50, 0'
],
[
'M50,0',
'C80,30 90,70 75,100',
'L60,80',
'L45,100',
'L30,80',
'L15,100',
'C10,70, 10,30,50, 0'
],[
'M20,0',
'C0,10 0,30 20,40',
'C0,60 0,70 40,100',
'C60,70 60,40 40,40',
'C60,30 60,10 20,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>
https://d3js.org/d3.v4.min.js