Skip to content

Instantly share code, notes, and snippets.

@rhettallain
rhettallain / spring_pendulum.py
Created March 6, 2014 15:06
springs vs strings
from visual import *
from visual.graph import *
fun1=gcurve(color=color.yellow)
fun2=gcurve(color=color.red)
g=vector(0,-9.8,0)
L=1.
t=0
dt=0.001
@rhettallain
rhettallain / electro_collision.py
Created March 11, 2014 14:13
electrostatic collision
from visual import *
from visual.graph import *
fun1=gcurve(color=color.yellow)
fun2=gcurve(color=color.red)
fun3=gcurve(color=color.cyan)
alpha=sphere(pos=(-1,0.05,0), radius=0.05, color=color.red, make_trail=True)
gold=sphere(pos=(0,0,0), radius=0.05, color=color.yellow, make_trail=True)
@rhettallain
rhettallain / circle_ball_pi.py
Created March 11, 2014 22:57
Ball moving in a circle to calculate pi
from visual import *
r=2.
ball=sphere(pos=(-r,0,0), radius=0.1, color=color.yellow, make_trail=True)
ball.v=vector(0,0.5,0)
start1=sphere(pos=ball.pos, radius=0.05, color=color.red)
t=0
dt=0.001
rt=ball.pos
@rhettallain
rhettallain / pingpong_air.py
Created March 12, 2014 15:25
Ping Pong Ball and a Golf Ball
from visual import *
from visual.graph import *
fun1=gcurve(color=color.yellow)
fun2=gcurve(color=color.white)
ground=box(pos=(0,0,0), length=.3, width=.3, height=0.01)
ball=sphere(pos=(0,0,0), radius=0.02, color=color.yellow,
make_trail=True)
@rhettallain
rhettallain / stick_rot.py
Created March 25, 2014 14:22
rotating stick
from visual import *
stick=box(pos=(0,0,0), length=1, width=.2, height=.2, color=color.cyan)
w=.5
t=0
dt=0.01
while True:
@rhettallain
rhettallain / ball_list.py
Created March 27, 2014 13:38
list of spheres
from visual import *
from random import *
print(uniform(2.2,4.4))
#ball1=sphere()
n=50
i=0
@rhettallain
rhettallain / car_collisions.py
Created April 14, 2014 15:23
collision physics
from visual import *
from visual.graph import *
fun1=gcurve(color=color.red)
fun2=gcurve(color=color.blue)
fun3=gcurve(color=color.yellow)
car1=box(pos=(-0.25, 0, 0), height=0.05, width=0.05, length=0.12, color=color.red)
car2=box(pos=(0.1, 0, 0), height=0.05, width=0.05, length=0.12, color=color.blue)
from pylab import *
#graph1 = gdisplay(title='Vertical Position vs. Time', xtitle ='t (sec)', ytitle ='y (m)', background=color.white)
#funct1=gcurve(color=color.white)
#floor = box (pos=(0,0,0), length=.4, height=0.05, width=.4, color=color.blue)
L = 120
theta0 = -pi/2
#ball2=sphere()
@rhettallain
rhettallain / goal_angular.py
Created June 27, 2014 14:05
soccer goal angular size
from pylab import *
#from visual import vector, dot, mag
## mark out the pitch
xlist=linspace(0,50.0,500)
ylist=linspace(-35.0, 35.0, 350)
X,Y = meshgrid(xlist, ylist)
@rhettallain
rhettallain / electric_pot_plot.py
Created July 14, 2014 18:48
contour plot of potential
import plotly.plotly as py
from plotly.graph_objs import *
from pylab import *
from visual import vector, norm, mag
#you need to add your own plot.ly credentials here
#py.sign_in(###########)
#electric constant
k=9e9