Uploaded July 2024 | Updated September 2026, 1 week ago
What happens when two circles collide in a p5.js canvas? In this video, I examine the math and implement idealized elastic collisions in a JavaScript physics simulation. This video supplements the Nature of Code book series in Chapter 6 which uses 3rd party physics libraries to handle collisions rather than a direct implementation. Code: thecodingtrain.com/challenges/184-elastic-collisions
π Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-coding-challenge-184-elastic-collisions
p5.js Web Editor Sketches:
πΉοΈ Elastic Collisions: editor.p5js.org/codingtrain/sketches/3DrBb8LCp
πΉοΈ Elastic Collisions - Quadtree: editor.p5js.org/codingtrain/sketches/z8n19RFz9
π₯ Previous: youtu.be/p7IGZTjC008?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ Next: youtu.be/MazpwQNdJYQ?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ All: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
References:
π The Nature of Code: natureofcode.com
π Pre-order The Nature of Code: nostarch.com/nature-code
π Elastic Collision: en.wikipedia.org/wiki/Elastic_collision
π 2-Dimensional Elastic Collisions without Trigonometry: vobarian.com/collisions/2dcollisions2.pdf
π Elastic Collisions Formula Derivation: dipamsen.github.io/notebook/page/collisions.pdf
Related Coding Challenges:
π youtu.be/IIrC5Qcb2G4
π youtu.be/OJxEcs0w_kE
π youtu.be/PoW8g67XNxA
π youtu.be/h5ZNcAPXxew
Timestamps:
0:00 Introduction
0:20 The Nature of Code book
1:22 Review background material
4:15 Collision Resolution
5:42 Start Coding
8:48 Add collide() function
10:17 Momentum and kinetic energy
14:15 Line of impact
16:44 Add the formulas
21:25 Simplify the code
22:57 Check for overlap
24:31 Check the particle's kinetic energy
25:48 Fix error
27:30 Add more particles
30:11 Optimizations
30:50 Outro
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
π Website: thecodingtrain.com
πΎ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: github.com/CodingTrain/Suggestion-Box
π‘ GitHub: github.com/CodingTrain
π¬ Discord: thecodingtrain.com/discord
π Membership: youtube.com/thecodingtrain/join
π Store: standard.tv/codingtrain
ποΈ Twitter: twitter.com/thecodingtrain
πΈ Instagram: instagram.com/the.coding.train
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: p5js.org
π p5.js Web Editor: editor.p5js.org
π Processing: processing.org
π Code of Conduct: github.com/CodingTrain/Code-of-Conduct
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new
#collisions #physicssimulation #collisiondetection #p5js #javascript
What happens when two circles collide in a p5.js canvas? In this video, I examine the math and implement idealized elastic collisions in a JavaScript physics simulation. This video supplements the Nature of Code book series in Chapter 6 which uses 3rd party physics libraries to handle collisions rather than a direct implementation. Code: thecodingtrain.com/challenges/184-elastic-collisions
π Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-coding-challenge-184-elastic-collisions
p5.js Web Editor Sketches:
πΉοΈ Elastic Collisions: editor.p5js.org/codingtrain/sketches/3DrBb8LCp
πΉοΈ Elastic Collisions - Quadtree: editor.p5js.org/codingtrain/sketches/z8n19RFz9
π₯ Previous: youtu.be/p7IGZTjC008?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ Next: youtu.be/MazpwQNdJYQ?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ All: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
References:
π The Nature of Code: natureofcode.com
π Pre-order The Nature of Code: nostarch.com/nature-code
π Elastic Collision: en.wikipedia.org/wiki/Elastic_collision
π 2-Dimensional Elastic Collisions without Trigonometry: vobarian.com/collisions/2dcollisions2.pdf
π Elastic Collisions Formula Derivation: dipamsen.github.io/notebook/page/collisions.pdf
Related Coding Challenges:
π youtu.be/IIrC5Qcb2G4
π youtu.be/OJxEcs0w_kE
π youtu.be/PoW8g67XNxA
π youtu.be/h5ZNcAPXxew
Timestamps:
0:00 Introduction
0:20 The Nature of Code book
1:22 Review background material
4:15 Collision Resolution
5:42 Start Coding
8:48 Add collide() function
10:17 Momentum and kinetic energy
14:15 Line of impact
16:44 Add the formulas
21:25 Simplify the code
22:57 Check for overlap
24:31 Check the particle's kinetic energy
25:48 Fix error
27:30 Add more particles
30:11 Optimizations
30:50 Outro
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
π Website: thecodingtrain.com
πΎ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: github.com/CodingTrain/Suggestion-Box
π‘ GitHub: github.com/CodingTrain
π¬ Discord: thecodingtrain.com/discord
π Membership: youtube.com/thecodingtrain/join
π Store: standard.tv/codingtrain
ποΈ Twitter: twitter.com/thecodingtrain
πΈ Instagram: instagram.com/the.coding.train
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: p5js.org
π p5.js Web Editor: editor.p5js.org
π Processing: processing.org
π Code of Conduct: github.com/CodingTrain/Code-of-Conduct
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new
#collisions #physicssimulation #collisiondetection #p5js #javascript




![Playing YOUR Versions of the Apple ][ Snake Game! - Showcase 1 #creativecoding #programming #shorts
For the first episode of this series, I react to a few submissions from the AppleSoft BASIC Snake Game Passenger Showcase. Next stop: Wave Function Collapse Showcase arriving next week!
π₯ BASIC Snake Game: https://youtu.be/7r83N3c2kPw
π¨ https://thecodingtrain.com/challenges/173-snake-applesoft-basic
π₯ WFC: https://youtu.be/rI_y2GAlQFM
π¨ https://thecodingtrain.com/challenges/171-wave-function-collapse
To learn how to submit yours, visit The Coding Train website and follow the guide: https://thecodingtrain.com/guides/passenger-showcase-guide
π Website: http://thecodingtrain.com/
πΎ Share Your Creation! https://thecodingtrain.com/Guides/community-contribution-guide.html
π© Suggest Topics: https://github.com/CodingTrain/Rainbow-Topics
π‘ GitHub: https://github.com/CodingTrain
π¬ Discord: https://discord.gg/hPuGy2g
π Membership: http://youtube.com/thecodingtrain/join
π Store: https://standard.tv/codingtrain
π Books: https://www.amazon.com/shop/thecodingtrain
ποΈ Twitter: https://twitter.com/thecodingtrain
πΈ Instagram: https://www.instagram.com/the.coding.train/
π₯ Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: https://p5js.org
π p5.js Web Editor: https://editor.p5js.org/
π Processing: https://processing.org
π Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct Playing YOUR Versions of the Apple ][ Snake Game! - Showcase 1 #creativecoding #programming #shorts](https://i.ytimg.com/vi/fAyGmUeNIFQ/mqdefault.jpg)





