A Pen by Frank Dumont on CodePen.
Created
May 16, 2019 04:55
-
-
Save idettman/07b69c2393df839eacddc3cefb23c38c to your computer and use it in GitHub Desktop.
Gaussian Distribution with Physics
This file contains hidden or 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
console.clear! | |
{ Engine, World, Composites, Bodies, Common } = Matter | |
engine = Engine.create document.body, | |
enable-sleeping: true | |
render: | |
options: | |
show-angle-indicator: true | |
wireframes: true | |
create-borders = let | |
offset = 5 | |
World.add engine.world, [ | |
Bodies.rectangle 400, 600 + offset, 800 + 2*offset, 50, is-static: true | |
Bodies.rectangle 800 + offset, 300, 50, 600 + 2*offset, is-static: true | |
Bodies.rectangle -offset, 300, 50, 600 + 2*offset, is-static: true | |
] | |
World.add engine.world, [ | |
Bodies.rectangle 185, 100, 420, 10, is-static: true, angle: 0.05*Math.PI | |
Bodies.rectangle 615, 100, 420, 10, is-static: true, angle: -1.05*Math.PI | |
] | |
World.add engine.world, Composites.stack 45, 100, 24, 8, 15, 15, (x, y, col, row) -> | |
Bodies.circle 45 + 30*col + 15*(row % 2), 180 + 30*row, 7.5, is-static: true | |
World.add engine.world, Composites.stack 65, 400, 24, 1, 25, 0, (x, y, col, row) -> | |
Bodies.rectangle x, y, 5, 430, is-static: true | |
Engine.run engine | |
ball-count = 200 | |
new-balls = -> | |
balls = Composites.stack 395, -25, 3, 1, 0, 0, (x, y, col, row) -> | |
x = Common.random 50, 750 | |
Bodies.circle x, y, 3, | |
friction: 0.0001 | |
restitution: 0.5 | |
density: 0.000001 | |
World.add engine.world, balls | |
ball-count := ball-count - 1 | |
if ball-count < 0 then | |
clear-interval interval | |
new-balls! | |
interval = set-interval new-balls, 150 |
This file contains hidden or 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
<script src="https://github.com/liabru/matter-js/releases/download/0.8.0-alpha/matter-0.8.0.js"></script> |
This file contains hidden or 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
body { | |
background: #222; | |
text-align: center; | |
} | |
canvas { | |
display: inline-block; | |
max-width: 100%; | |
max-height: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment