



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1 bounce.py
from visual import *
floor = box ( pos =(0 ,0 ,0) , length =4 , height =0.5 , width =4 , color = color. blue ) ball = sphere ( pos =(0 ,4 ,0) , radius =1 , color = color. red ) ball. velocity = vector (0 , -1 ,0) dt = 0.
while 1: rate (100)
ball. pos = ball. pos + ball. velocity * dt
if ball. y < ball. radius : ball. velocity. y = - ball. velocity. y else : ball. velocity. y = ball. velocity. y - 9.8* dt
rate (100)
ball. pos = ball. pos + ball. velocity * dt
if ball. y < ball. radius : ball. velocity. y = - ball. velocity. y else : ball. velocity. y = ball. velocity. y - 9.8* dt
floor=box(pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)
from visual import *
wallR = box ( pos =( 4 ,0 ,0) , axis =( -1 ,0 ,0) , length =0.3 , height =8 , width =8) wallL = box ( pos =( -4 ,0 ,0) , axis =( 1 ,0 ,0) , length =0.3 , height =8 , width =8)
edge = thk =0. wallR = box ( pos =( edge /2. ,0 ,0) , axis =( -1 ,0 ,0) , length = thk , height = edge , width = edge ) wallL = box ( pos =( - edge /2. ,0 ,0) , axis =( 1 ,0 ,0) , length = thk , height = edge , width = edge )
capture [OPTIONAL] Include a capture of your animation window in your Word document. in Windows
3 bounce2.py - your version
from visual import *
side = 4. thk = 0.
from visual import *
scene. autoscale = scene. range =10.
def force ( pos , vel , t ): result = vector (0 ,0 ,0) kx =1. ky =1. result. x = - kx * pos. x result. y = - ky * pos. y result. z = return result
ball = sphere ( radius =0.5 , pos = vector (0 ,0 ,0) , track = curve ( radius =0.05) , mass =1.0) ball. vel = vector (5 ,5 ,0) t = dt =0.
while true : rate (100) t = t + dt ball. pos = ball. pos + ball. vel * dt ball. vel = ball. vel + force ( ball. pos , ball. vel , t )* dt ball. track. append ( pos = ball. pos )
[OPTIONAL] If you are completely done and have some time to play, try adding these lines, a set at a time. viewpoint