Skip to content

Instantly share code, notes, and snippets.

@trytuna
Last active June 22, 2018 08:12
Show Gist options
  • Save trytuna/12c72b13a81c07dbee61c22f218ebee7 to your computer and use it in GitHub Desktop.
Save trytuna/12c72b13a81c07dbee61c22f218ebee7 to your computer and use it in GitHub Desktop.
Film Flowers Petal Starter Code
license: gpl-3.0
<!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>
// draw petal
var petals = [
[
'M0,0',
'C50,40 50,70 20,100',
'L0,85',
'L-20,100',
'C-50,70 -50,40 0,0'
],
[
'M0,0',
'C0,0 0,70 60,100',
'L20,100',
'C10,120 -10,120 -20,100',
'L-60,100',
'C0,70 0,0 0,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.join(' ')})
.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