Skip to content

Instantly share code, notes, and snippets.

@vasturiano
Last active March 29, 2023 10:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasturiano/784cbb2a21fa133a41c83768d2e67f0d to your computer and use it in GitHub Desktop.
Save vasturiano/784cbb2a21fa133a41c83768d2e67f0d to your computer and use it in GitHub Desktop.
Force Beeswarm
<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