viz = (svg, numStars) => {
const size = numStars || 20
const starData = []
for(let i = 0; i < size; i++){
starData.push({
points,
})
}
const getRandomRotation = () => {
const minR = 0
const maxR = 360
return minR + Math.random() * (maxR - minR)
}
const leaderScale = d3.scaleLinear().domain([0, size]).range([0, 1])
const color = (d) => d3.interpolateRdPu(leaderScale(d))
const ordinalColor = d3.scaleOrdinal().range(colors)
const height = 500
svg.selectAll(".stars").remove()
svg.selectAll(".stars")
.data(starData)
.enter()
.append("polygon")
.attr("points", d => d.points)
.attr("opacity", 1)
.attr("class", "stars")
.attr("fill", (d,i) => ordinalColor(i))
.attr("transform", (d, i) => {
const x = i % 2 === 0 ? width: 0
return `translate(${x},${height}) rotate(0)`
})
.transition()
.duration(1500)
.attr("transform", (d, i) => {
let y = (height / 2) * Math.random()
let x = (width / 4) + (width / 4) * Math.random()
if (i % 2 !== 0) {
x = (width / 2) + (width / 4) * Math.random()
}
return `translate(${x},${y}) rotate(${getRandomRotation()})`
})
.ease(d3.easeCubicOut)
.attr('opacity', 0)
return svg
}