from __future__ import division ## treat integers as real numbers in division from visual import * from visual.graph import * scene.width=600 scene.height = 760 ## constants and data g = 9.8 mball = 1 ## change this to the measured mass of the yellow sinker L0 = 1 ## change this to the relaxed length of your spring ks = 1 ## change this to the spring constant you measured deltat = 1 ## change this to be about 1/1000 of your measured period t = 0 ## start counting time at zero ## objects ceiling = box(pos=(0,0,0), size = (0.2, 0.01, 0.2)) ## origin is at ceiling ball = sphere(pos=(0,-L0,0), radius=0.025, color=color.yellow) ## note: spring initially compressed spring = helix(pos=ceiling.pos, color=color.orange, thickness=.003, coils=40, radius=0.015) spring.axis = ball.pos - ceiling.pos ## initial values ball.p = mball*vector(0,0,0) ## improve the display scene.autoscale = 0 ## don't let camera zoom in and out as ball moves scene.center = vector(0,-L0,0) ## move camera down to improve display visibility ## calculation loop while t < 60: ## make this short to read period off graph ## calculate force on ball by spring (note: requires calculation of L_vector) ## calculate net force on ball (note: has two contributions) ## apply momentum principle ## update position ## update axis of spring ## update time t = t + deltat