I am trying to create a pendulum with oscillating string and mass which is expected to oscillate for a period of time and then stop. From what I wrote, the mass could not stop oscillating. Kindly help me out.
import pyglet
import pymunk
import chipmunk
from pymunk import Vec2d
from pymunk.pyglet_util import DrawOptions
window = pyglet.window.Window(1300,700,"Oscillation",resizable=False)#
W,H
options=DrawOptions()
space=pymunk.Space()
space.gravity= 0,-100
b0= space.static_body
p0= 100,200
body= pymunk.Body(mass=0.5, moment =1)
body.position = (100,50)
circle= pymunk.Circle(body, radius=20)
joint= pymunk.constraint.DampedSpring(b0, body,p0, (0,0), 100, 10, 0)
space.add(body, circle, joint)
@window.event
def on_draw():
window.clear()
space.debug_draw(options)
def update(dt):
space.step(dt)
if __name__=="__main__":
pyglet.clock.schedule_interval(update,1.0/60)
pyglet.app.run()
You did not provide damping in the last parameter of the call:
So it will oscillate forever. Put some amount of damping and it should slow down.