Grifter

N body sim using VPython

Nov 27th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #Libraries
  2. from visual import *
  3. from random import randint
  4.  
  5. #Variables
  6. particles = []
  7. num = 38
  8. mass = 10000000000000
  9. dt = 0.03
  10. G = 6.67384*10**(-11)
  11.  
  12. #Object Gen
  13. for i in xrange(0,num):
  14.     particles.append(sphere(pos = vector(randint(-100,100),randint(-100,100),randint(-100,100)), f = vector(0,0,0), v = vector(0,0,0), a = vector(0,0,0)))
  15.  
  16. #Main loop
  17. while True:
  18.     rate(1/dt)
  19.     for i in particles:
  20.         i.f = vector(0,0,0)
  21.         for j in particles:
  22.             if i.pos - j.pos != vector(0,0,0):
  23.                 i.f = i.f + ((G*mass**2)/mag(i.pos-j.pos)**2)*(j.pos-i.pos)
  24.         i.a = i.f/mass
  25.         i.v = i.v + i.a*dt
  26.         i.pos = i.pos + i.v*dt
Advertisement
Add Comment
Please, Sign In to add comment