2.5 Gravitational Attraction - The Nature of Code

Subscribers:
1,740,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