#!/usr/bin/env python
import numpy as n
import scipy.constants as c
class Body:
def __init__(self,xx,xy,vx,vy,m):
self.coord = n.array([xx,xy],dtype='float')
self.speed = n.array([vx,vy],dtype='float')
self.mass = m
self.color = n.random.rand(3)
def __str__(self):
return """Planet:
Coordinates:\t%05.2f\t%05.2f
Velocity:\t%05.2f\t%05.2f
Mass:\t\t%05.2e""" % (self.coord[0],self.coord[1],self.speed[0],self.speed[1],self.mass)
def gravitate(self,other):
if self == other:
return 0
if other.__class__ == self.__class__:
e_r = self.coord-other.coord
a = -6e-3*other.mass/n.inner(e_r,e_r)*e_r
self.speed += a
else:
raise TypeError, 'This is no planet'
def move(self):
self.coord += self.speed
if __name__ == '__main__':
print 'This is a test body'
b = Body(1.1,1.2,.1,1,1e3)
print b