Skip to content

Instantly share code, notes, and snippets.

@rhettallain
rhettallain / fluker_collision.py
Created April 8, 2013 21:25
Here is a vpython model that looks at a collision between two objects.
from visual import *
from visual.graph import *
gra=gcurve(color=color.cyan)
dj=sphere(pos=(-2,0,0), radius=0.15, color=color.red)
dude=sphere(pos=(0,0,0), radius=0.1, color=color.cyan)
dj.m=100
dude.m=65
@rhettallain
rhettallain / space_agency_model.py
Created May 21, 2013 14:31
Orbital Motion to model the orbit (with thrust) in the iPhone app Space Agency
from visual import *
Earth=sphere(pos=vector(0,0,0), radius =1, material=materials.earth)
R=2.75 #orbita radius in terms of radius of the planet
GM=1.47 #GM as determined from the game
v=sqrt(GM/R) #starting speed for a circular orbit
rt=0.0338 #this is the acceleration due to the rocket
#sc is the spacecraft
@rhettallain
rhettallain / two_drunk_lost_woods.py
Created September 5, 2013 14:06
A random walk with two drunks in the woods looking for each other.
from pylab import *
from random import *
n=0
x1p=[0]
y1p=[0]
x1=0
y1=0
@rhettallain
rhettallain / square_spiral.py
Created September 6, 2013 20:20
Spiral square
from pylab import *
vx=0
vy=1
x=0
y=0
xp=[0]
yp=[0]
@rhettallain
rhettallain / drunk_lost.py
Created September 10, 2013 12:19
Two drunks lost in the woods. Random walk search pattern
rom pylab import *
from random import *
def drunk(s):
# s is the distance the two drunks start from each other
n=0
x1=0
y1=0
@rhettallain
rhettallain / guass_law_cube.py
Created October 31, 2013 17:19
Here is a numerical calculation of the electric flux through a cube shaped surface due to a point charge on the inside.
from __future__ import division
from visual import *
#import pylab as pb
scene2=display(background=color.white)
#scene2.visible=False
L=1.
@rhettallain
rhettallain / oned_collisions.py
Last active December 28, 2015 03:48
This calculation uses vpython to model one dimensional collisions between two carts.
from visual import *
from visual.graph import *
#import pylab as pb
# the pylab module is used for making prettier graphs
### These are the three curves for plotting
fun1=gcurve(color=color.cyan)
fun2=gcurve(color=color.red)
fun3=gcurve(color=color.yellow)
@rhettallain
rhettallain / test_plotly.py
Created December 18, 2013 21:16
Here is a python code to make a simple plot in plotly
import plotly
py = plotly.plotly(username='**username**', key='**put your api key here**')
y=0
t=0
dt=0.01
g=9.8
v=4
@rhettallain
rhettallain / moving_ball.py
Last active January 4, 2016 06:19
A simple vpython program with a moving ball
from visual import *
t=0
dt=0.01
g=vector(0,-9.8,0)
ball = sphere(pos=(-1,1,0), radius=.15, color=color.cyan)
ball.v=vector(0.1,0,0)
floor=box(pos=(0,0,0), length=2, width=1, height=.1, color=color.blue)
@rhettallain
rhettallain / ball_bounce1.py
Created January 29, 2014 23:18
ball bounce with zero energy loss
from visual import *
g=vector(0,-9.8,0)
ball=sphere(pos=(0,1,0), radius=0.05, material=materials.shiny)
ball.p=vector(0,0,0)
ball.m=0.1
t=0
dt=0.001
floor = box(length=1, width=1, height=0.05, pos=vector(0,0,0), color=color.blue)