Created
July 13, 2017 22:27
-
-
Save mwcraig/5eccd7bfdd909d5640ee6fe524919e6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = """ | |
me: Matt Craig, Professor Physics and Astronomy, MSUM (small undergrad public college) | |
I AM NOT THE MAIN VPYTHON DEV. | |
Project home page: vpython.org | |
install: | |
pip install vpython | |
or | |
conda install -c vpython vpython | |
run: | |
python Bounce.py | |
BONUS: runs in a jupyter notebook too | |
github: | |
https://github.com/BruceSherwood/vpython-jupyter | |
examples: look in "Demos" or "Demos_no_notebook" | |
no-install alternative: glowscript.org | |
textbook: | |
Matter and Interactions, 4th Ed, Chabay and Sherwood, Wiley | |
""" | |
from vpython import * | |
scene.caption = """Right button drag or Ctrl-drag to rotate "camera" to view scene. | |
To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel. | |
On a two-button mouse, middle is left + right. | |
Touch screen: pinch/extend to zoom, swipe or two-finger rotate.""" | |
side = 4.0 | |
thk = 0.3 | |
s2 = 2*side - thk | |
s3 = 2*side + thk | |
wallR = box (pos=vector( side, 0, 0), size=vector(thk, s2, s3), color = color.red) | |
wallL = box (pos=vector(-side, 0, 0), size=vector(thk, s2, s3), color = color.red) | |
wallB = box (pos=vector(0, -side, 0), size=vector(s3, thk, s3), color = color.blue) | |
wallT = box (pos=vector(0, side, 0), size=vector(s3, thk, s3), color = color.blue) | |
wallBK = box(pos=vector(0, 0, -side), size=vector(s2, s2, thk), color = color.gray(0.7)) | |
ball = sphere (pos=vec(1,1.5,0), color = color.green, radius = 0.4, make_trail=True, retain=200) | |
ball.mass = 1.0 | |
ball.p = vector (-0.15, -0.23, +0.27) | |
side = side - thk*0.5 - ball.radius | |
dt = 0.3 | |
while True: | |
rate(200) | |
ball.pos = ball.pos + (ball.p/ball.mass)*dt | |
if not (side > ball.pos.x > -side): | |
ball.p.x = -ball.p.x | |
if not (side > ball.pos.y > -side): | |
ball.p.y = -ball.p.y | |
if not (side > ball.pos.z > -side): | |
ball.p.z = -ball.p.z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment