mtrajk / bouncing-balls Goto Github PK
View Code? Open in Web Editor NEWBouncing balls simulation using plain JavaScript
Home Page: https://mtrajk.github.io/bouncing-balls/
License: MIT License
Bouncing balls simulation using plain JavaScript
Home Page: https://mtrajk.github.io/bouncing-balls/
License: MIT License
@MTrajK thx for your code :) Im find some strange thing: if the bottom line is completely filled with balls, then the balls are shaking.
Hello! I find that with this code (both in your demo and in my re-implementation in my program) there happens to be the problem of the "dancing balls". Sometimes balls that come into contact start "dancing" around each other instead of bouncing.
As I have found out that happens because in certain circumstances the collided balls do not get repositoned outside each other correctly. The error is in these two lines:
bouncing-balls/src/js/balls.js
Lines 56 to 57 in 9edad0f
it should instead be
this.position = this.position.add((this.position - ball.position).tryNormalize().mult(diff));
ball.position = ball.position.add((ball.position - this.position).tryNormalize().mult(diff));
So that we reposition the balls not in their speeds directions, which might be directed anywhere and won't always take the balls to positions where they separate. But rather in the direction of a line that passes through both of their centers, in opposite directions, effectively pulling them away from each other.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.