## Oct. 1, 2002, A. Middleton ## orbittype.py ## This code simulates the motion of an object subject to a force ## from another object that is fixed at the origin (0,0,0). from visual import * scene.autoscale = 0 forcetype = -2 ## draw object at origin in a suggestive yellow color sphere(radius=0.2, color=color.yellow) ## this will be the flying object, suggestively named and ## colored earth = sphere(radius = 0.1, color=color.blue, pos = (1,0,0)) ## Give it a nonzero velocity, so that it will not plummet earth.vel = vector(0,0.8,0) dt = 0.01 while 1: rate(80) earth.pos = earth.pos + dt * earth.vel earth.vel = earth.vel + dt * (-earth.pos*mag(earth.pos)**forcetype)