Skip to content

Instantly share code, notes, and snippets.

@preziotte
Last active March 16, 2016 05:57
Show Gist options
  • Save preziotte/fea5d3e67a8a3f0fcee2 to your computer and use it in GitHub Desktop.
Save preziotte/fea5d3e67a8a3f0fcee2 to your computer and use it in GitHub Desktop.
Butterfly Big Bang
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background-color: #36393B;
}
svg {
position: absolute;
height: 100%;
width: 100%;
}
svg path {
opacity: .5;
fill: none;
stroke: #EEE6AB;
stroke-width: 1px;
stroke-linecap: rounded;
}
.frame {
fill: none;
stroke: #000;
}
.axis text {
font: 10px sans-serif;
fill: white;
}
.axis line,
.axis circle {
fill: none;
stroke: #EEE6AB;
stroke-dasharray: 1,4;
}
.axis {
opacity: 0;
-webkit-transition: opacity .5s linear;
-moz-transition: opacity .5s linear;
-o-transition: opacity .5s linear;
transition: opacity .5s linear;
}
svg:hover .axis {
opacity: 0.5;
}
.axis :last-of-type circle {
stroke: #EEE6AB;
stroke-dasharray: none;
}
.line {
fill: none;
stroke: #EEE6AB;
stroke-width: 1px;
stroke-dasharray: 40 10 90 10;
stroke-dasharray: 10 40 10 90;
stroke-dashoffset: 0;
-webkit-animation: dash 1s linear infinite, throb 10s ease infinite;
-moz-animation: dash 1s linear infinite, throb 10s ease infinite;
animation: dash 1s linear infinite, throb 10s ease infinite;
}
@keyframes dash {
100% {
stroke-dashoffset: 150;
}
}
@-webkit-keyframes dash {
100% {
stroke-dashoffset: 150;
}
}
@keyframes throb {
0% {
transform: scale(.1);
}
50% {
transform: scale(1);
}
100% {
transform: scale(.1);
}
}
@-webkit-keyframes throb {
0% {
transform: scale(.1);
}
50% {
transform: scale(1);
}
100% {
transform: scale(.1);
}
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// http://bl.ocks.org/mbostock/4583749
// https://en.wikipedia.org/wiki/Butterfly_curve_(transcendental)
// http://calculus-geometry.hubpages.com/hub/Butterfly-Curves-in-Polar-Coordinates-on-a-Graphing-Calculator
var data2 = d3.range(0, 12 * Math.PI, .01).map(function(t) {
var r = (7 - Math.sin(t) + 2*Math.sin(3*t) + 2*Math.sin(5*t) - Math.sin(7*t) + 0.4*Math.sin(9*t) - 0.4*Math.sin(25*t) + 3*Math.cos(2*t) - 2*Math.cos(4*t) - 0.2*Math.cos(26*t));
return [t, r];
});
var data = d3.range(0, 20 * Math.PI, .01).map(function(t) {
var r = Math.exp(Math.sin(t))-2*Math.cos(4*t)+Math.pow(Math.sin((2*t-Math.PI)/24),5);
return [t, r*100];
});
var width = window.innerWidth,
height = window.innerHeight-20,
radius = Math.min(width, height) / 2 - 30;
var r = d3.scale.linear()
.domain([0, 15])
.range([0, radius]);
var line = d3.svg.line.radial()
.radius(function(d) { return r(d[1]); })
.angle(function(d) { return -d[0] + Math.PI / 2; });
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var gr = svg.append("g")
.attr("class", "r axis")
.selectAll("g")
.data(r.ticks(5).slice(1))
.enter().append("g");
gr.append("circle")
.attr("r", r);
// gr.append("text")
// .attr("y", function(d) { return -r(d) - 4; })
// .attr("transform", "rotate(15)")
// .style("text-anchor", "middle")
// .text(function(d) { return d; });
var ga = svg.append("g")
.attr("class", "a axis")
.selectAll("g")
.data(d3.range(0, 360, 30))
.enter().append("g")
.attr("transform", function(d) { return "rotate(" + -d + ")"; });
ga.append("line")
.attr("x2", radius);
// ga.append("text")
// .attr("x", radius + 6)
// .attr("dy", ".35em")
// .style("text-anchor", function(d) { return d < 270 && d > 90 ? "end" : null; })
// .attr("transform", function(d) { return d < 270 && d > 90 ? "rotate(180 " + (radius + 6) + ",0)" : null; })
// .text(function(d) { return d + "°"; });
console.log(data);
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
</script>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment