D3 example
How do I make an d3 example?
Juts fooling around with some examples from the amazing d3.js library. What is a d3 example? How do you make a d3 example? This script and codes were developed by Theun on 23 July 2022, Saturday.
D3 example - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>D3 example </title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<html> <head> <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"></script> </head> <body> </body>
</html> <script src='http://mbostock.github.com/d3/d3.js?1.29.1'></script> <script src="js/index.js"></script>
</body>
</html>
D3 example - Script Codes CSS Codes
body { background: #333;
}
ellipse { fill: #ddd;
}
path { fill: none; stroke: #ddd; stroke-linecap: round;
}
.mid { stroke-width: 4px;
}
.tail { stroke-width: 2px;
}
D3 example - Script Codes JS Codes
var w = 960, h = 500, n = 100, m = 12, degrees = 180 / Math.PI;
var spermatozoa = d3.range(n).map(function() { var x = Math.random() * w, y = Math.random() * h; return { vx: Math.random() * 2 - 1, vy: Math.random() * 2 - 1, path: d3.range(m).map(function() { return [x, y]; }), count: 0 };
});
var svg = d3.select("body").append("svg:svg") .attr("width", w) .attr("height", h);
var g = svg.selectAll("g") .data(spermatozoa) .enter().append("svg:g");
var head = g.append("svg:ellipse") .attr("rx", 6.5) .attr("ry", 4);
g.append("svg:path") .map(function(d) { return d.path.slice(0, 3); }) .attr("class", "mid");
g.append("svg:path") .map(function(d) { return d.path; }) .attr("class", "tail");
var tail = g.selectAll("path");
d3.timer(function() { for (var i = -1; ++i < n;) { var spermatozoon = spermatozoa[i], path = spermatozoon.path, dx = spermatozoon.vx, dy = spermatozoon.vy, x = path[0][0] += dx, y = path[0][1] += dy, speed = Math.sqrt(dx * dx + dy * dy), count = speed * 10, k1 = -5 - speed / 3; // Bounce off the walls. if (x < 0 || x > w) spermatozoon.vx *= -1; if (y < 0 || y > h) spermatozoon.vy *= -1; // Swim! for (var j = 0; ++j < m;) { var vx = x - path[j][0], vy = y - path[j][1], k2 = Math.sin(((spermatozoon.count += count) + j * 3) / 300) / speed; path[j][0] = (x += dx / speed * k1) - dy * k2; path[j][1] = (y += dy / speed * k1) + dx * k2; speed = Math.sqrt((dx = vx) * dx + (dy = vy) * dy); } } head.attr("transform", function(d) { return "translate(" + d.path[0] + ")rotate(" + Math.atan2(d.vy, d.vx) * degrees + ")"; }); tail.attr("d", function(d) { return "M" + d.join("L"); });
});
Developer | Theun |
Username | tjoen |
Uploaded | July 23, 2022 |
Rating | 4 |
Size | 2,392 Kb |
Views | 52,624 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
SVG pong | 3,818 Kb |
Touch Slider | 3,587 Kb |
Those kids... | 3,390 Kb |
Responsive activity calendar | 3,850 Kb |
Generative art from rectangleworld | 5,196 Kb |
Canvas Buldings | 2,737 Kb |
A Pen by Theun | 2,240 Kb |
ROTATING IMAGE SLIDER WITH JQUERY | 5,062 Kb |
Love is in the air... | 2,642 Kb |
Three.js shooter template | 6,268 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Custom Select Element | Agrayson | 3,616 Kb |
Comparison of Roboto Draft vs Roboto | Jxnblk | 2,880 Kb |
React JS Movie Info App | MTushar | 4,870 Kb |
JQuery FullScreen Overlay | _codemics | 2,252 Kb |
Hello People | Danburrows | 2,365 Kb |
Pure CSS albums gallery | Renaudtertrais | 2,978 Kb |
Incremental game | Eprouver | 5,868 Kb |
Personal Website Redesign v2.0 | DevItWithDavid | 5,168 Kb |
Example SVGZ Data URI | Joeyhoer | 2,981 Kb |
Bootstrap 3 Price Table | Honglio | 2,655 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!