Last active
March 29, 2023 10:07
-
-
Save vasturiano/784cbb2a21fa133a41c83768d2e67f0d to your computer and use it in GitHub Desktop.
Force Beeswarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<style>body { margin: 0; }</style> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.5/dat.gui.js"></script> | |
<script src="//unpkg.com/d3-force-pod"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.10.2/d3.min.js"></script> | |
</head> | |
<body> | |
<script> | |
const f = d3.forceManyBody().strength(0); | |
d3ForcePod()(document.body) | |
.nodeColor('midnightblue') | |
.genNodes({ | |
density: 2e-4, | |
radiusRange: [6, 6], | |
velocityRange: [0, 0] | |
}) | |
.addForce(f); | |
// Controls | |
const controls = { strength: 0 }; | |
const gui = new dat.GUI(); | |
gui.add(controls, 'strength').min(-1).max(1).step(0.01).onChange(s =>f.strength(s)); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment