2.5 Gravitational Attraction - The Nature of Code
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