2.6 Mutual Attraction - The Nature of Code @TheCodingTrain
2.6 Mutual Attraction - The Nature of Code  @TheCodingTrain
Uploaded March 2022 | Updated November 2026, 20 hours ago
Finishing off Chapter 2 on forces, let's look at an "N-Body Simulation" where all movers experience gravitational attraction with all other movers! thecodingtrain.com/tracks/the-nature-of-code-2/noc/2-forces/6-mutual-attraction

p5.js Web Editor Sketches:
πŸ•ΉοΈ Mutual Attraction (N-Body): editor.p5js.org/codingtrain/sketches/bEt7eLZ6Y
πŸ•ΉοΈ Mutual Attraction (N-Body) with Barnes Hut: editor.p5js.org/codingtrain/sketches/joXNoi9WL

πŸŽ₯ Previous video: youtu.be/EpgB3cNhKPM?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
πŸŽ₯ Next video: youtu.be/DMg-WRfNB60?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
πŸŽ₯ All videos: youtube.com/playlist?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM

Links discussed in this video:
πŸ”— Newton's law of universal gravitation (Wikipedia): en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation
πŸ”— Nature of Code Book - 2.10 Everything Attracts (or Repels) Everything: natureofcode.com/book/chapter-2-forces/#210-everything-attracts-or-repels-everything
πŸ”— p5.Vector rotate(): p5js.org/reference/#/p5.Vector/rotate
πŸ”— N-Body Choreographies research paper by Montaldi and Steckles: personalpages.manchester.ac.uk/staff/j.montaldi/Choreographies/about.html
πŸ”— N-Body Choreographies animation tool by Dan Gries: personalpages.manchester.ac.uk/staff/j.montaldi/Choreographies

Other videos mentioned in this video:
πŸŽ₯ 2.5 Gravitational Attraction - The Nature of Code: youtu.be/EpgB3cNhKPM
πŸŽ₯ 2.1 Simulating Forces: Gravity and Wind - The Nature of Code: youtu.be/Uibl0UE4VH8
πŸŽ₯ 5.1 Autonomous Steering Agents - The Nature of Code: youtu.be/P_xJMH8VvAE
πŸŽ₯ 3.1 Angles and Rotation - The Nature of Code: youtu.be/DMg-WRfNB60
πŸŽ₯ Coding Challenge #98.1 - Quadtree: youtu.be/OJxEcs0w_kE

Timestamps:
0:00 Introducing Today's Topic
0:30 Recap Single attractor system
1:20 The two body problem
2:21 Euler Integration
2:53 Other integration options
4:00 Coding 2-body simulation
7:56 The three body problem
8:15 Coding 3-body simulation
9:04 Refactoring for n-body
10:48 Adding a fourth mover
11:38 Looking at initial states
12:03 Shape 1: donut
13:33 The p5 Vector rotate() function
16:12 Trying out different variations
17:34 Looking at efficiency
19:10 Adding the sun
20:46 Looking at other examples
21:21 Exercise for viewers
22:09 Invite to chapter 3 and goodbye

πŸš‚ Website: thecodingtrain.com
πŸ‘Ύ Share Your Creation! thecodingtrain.com/Guides/community-contribution-guide.html
🚩 Suggest Topics: github.com/CodingTrain/Rainbow-Topics
πŸ’‘ GitHub: github.com/CodingTrain
πŸ’¬ Discord: discord.gg/hPuGy2g
βœͺ Nebula: go.nebula.tv/codingtrain
πŸ’– Membership: youtube.com/thecodingtrain/join
πŸ›’ Store: standard.tv/codingtrain
πŸ“š Books: amazon.com/shop/thecodingtrain
πŸ–‹οΈ Twitter: twitter.com/thecodingtrain
πŸ“Έ Instagram: instagram.com/the.coding.train

πŸŽ₯ Coding Challenges: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
πŸŽ₯ Intro to Programming: 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/website/issues/new
2.6 Mutual Attraction - The Nature of CodeSpooooooooky ml5.js!Use code CHOOCHOO for 25% off. Pre-ordering direct from me comes with a bonus bookmark and sticker!Preshow! ITP/IMA Spring Show 20223D Pose Estimation with ml5.jsOpen Source Saturday! (Live from the Attic)Coding Challenge 177: Soft Body Physics3.6 Graphing Sine Wave - Nature of CodeA promise is a promise… Jamming with Your Tunes! 🎡 #programming #music #shortsWhat is Transformers.js?Coding Challenge Session: Local Browser Conversational Chatbot (STT, TTS, and more?)Coding Challenge 180: Falling Sand
The Coding Train |

2.6 Mutual Attraction - The Nature of Code

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER