Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / raspberrypipicalc.py
Created March 8, 2017 20:49
This is the code to run on raspberry pi for an interactive pi-day poster
#!/usr/bin/python
# Example using a character LCD connected to a Raspberry Pi or BeagleBone Black.
import time
import Adafruit_CharLCD as LCD
import Adafruit_CharLCD as LCD
import turtle
import random
from math import sqrt
from gpiozero import Button
@rhettallain
rhettallain / train_start.py
Created May 28, 2014 15:27
A model of a starting train with couplings
from visual import *
from visual.graph import *
## Setting up graphs for three of the cars
fun1=gcurve(color=color.cyan)
fun2=gcurve(color=color.yellow)
fun3=gcurve(color=color.red)
###
@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 / 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 / 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 / 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 / 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 / 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]