Skip to content

Instantly share code, notes, and snippets.

@n3tr
Last active January 26, 2018 06:25
Show Gist options
  • Save n3tr/ae57e50899e116d315df79f29e807e0f to your computer and use it in GitHub Desktop.
Save n3tr/ae57e50899e116d315df79f29e807e0f to your computer and use it in GitHub Desktop.
Film Flowers Petal Starter Code
license: mit
<!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'
],
[
'M50,0',
'C80,30 90,70, 75,100',
'L50,65',
'L25,100',
'C10,70 20,30 50,0',
'Z'
],
[
'M50,0',
'C100,30 80,80 75,100',
'C60,80 40,80 25,100',
'C20,80 0,30 50,0',
'M50,40',
'C55,45 60,60 60,60',
'C50,65 50,65 40,60',
'C40,60 45,45 50,40'
],
[
'M50,0',
'C100,50 100,90 90,100',
'L80,90 70,100 60,90 50,100',
'L40,90 30,100 20,90 10,100',
'C0,90 0,50 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