2.5 Gravitational Attraction - The Nature of Code

Subscribers:
1,750,000
Published on ● Video Link: https://www.youtube.com/watch?v=EpgB3cNhKPM



Duration: 16:37
95,754 views
2,570


In this video, I demonstrate how to apply Newton’s Law of Universal Gravitation in p5.js using vectors and forces. Code: https://thecodingtrain.com/tracks/the-nature-of-code-2/noc/2-forces/5-gravitational-attraction

πŸš€ Watch this video ad-free on Nebula https://nebula.tv/videos/the-coding-train-yt-2-5-gravitational-attraction-the-nature-of-code

p5.js Web Editor Sketches:
πŸ•ΉοΈ Gravitational Attraction: https://editor.p5js.org/codingtrain/sketches/MkLraatd
πŸ•ΉοΈ Attraction Exercise: https://editor.p5js.org/codingtrain/sketches/ImehzZuCU

πŸŽ₯ Previous video: https://youtu.be/DxFDgOYEoy8?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
πŸŽ₯ Next video: https://youtu.be/GjbKsOkN1Oc?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
πŸŽ₯ All videos: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM

References:
πŸ”— Newton's law of universal gravitation: https://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation
πŸ”— 2.9 Gravitational Attraction: https://natureofcode.com/book/chapter-2-forces/#29-gravitational-attraction

Videos:
πŸŽ₯ Acceleration Vector: https://youtu.be/T84AWnntxZA
πŸŽ₯ Attraction and Repulsion Forces: https://youtu.be/OAcXnzRNiCY

Timestamps:
0:00 It's time for gravitational attraction!
1:17 Diagram the mover and attractor
1:43 Formula for gravitational attraction
3:51 Add an attractor
5:00 Add an attractor class
7:06 Revisit the diagram
7:52 Add an attract function
10:46 Role of distance squared
11:52 Constrain the range of distance squared
12:33 Give mover an inital velocity
13:25 Give the background some alpha
13:44 Add an array of mover objects
15:12 Possible variations

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

πŸš‚ Website: http://thecodingtrain.com/
πŸ‘Ύ Share Your Creation! https://thecodingtrain.com/guides/passenger-showcase-guide
🚩 Suggest Topics: https://github.com/CodingTrain/Suggestion-Box
πŸ’‘ GitHub: https://github.com/CodingTrain
πŸ’¬ Discord: https://thecodingtrain.com/discord
βœͺ Nebula: https://go.nebula.tv/codingtrain
πŸ’– Membership: http://youtube.com/thecodingtrain/join
πŸ›’ Store: https://standard.tv/codingtrain
πŸ–‹οΈ 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

This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/thecodingtrain.com/issues/new

#forbeginners #javascript #p5js