Jul-24-2020, 02:36 PM
Hi everybody.
I have a piece of code, generating a bouncing ball with equal time intervals (collision points occur in equal time durations). What I need to do is making this ball to occur in rhythmic intervals and I want to determine this time myself. So to conclude, I want a ball that hit the floor for example 6 times and time duration between collisions are determined by myself.
here is the code I have. what should I do to change is to what I want?
import turtle
wn=turtle.Screen()
wn.bgcolor('black')
wn.title('bouncing ball simulator')
ball=turtle.Turtle()
ball.shape('circle')
ball.color('green')
ball.penup()
ball.speed(0)
ball.goto(0,200)
ball.dy=0
gravity=0.1
while True:
ball.dy-=gravity
ball.sety(ball.ycor()+ball.dy)
if ball.ycor()<-300:
ball.dy*=-1
I have a piece of code, generating a bouncing ball with equal time intervals (collision points occur in equal time durations). What I need to do is making this ball to occur in rhythmic intervals and I want to determine this time myself. So to conclude, I want a ball that hit the floor for example 6 times and time duration between collisions are determined by myself.
here is the code I have. what should I do to change is to what I want?
import turtle
wn=turtle.Screen()
wn.bgcolor('black')
wn.title('bouncing ball simulator')
ball=turtle.Turtle()
ball.shape('circle')
ball.color('green')
ball.penup()
ball.speed(0)
ball.goto(0,200)
ball.dy=0
gravity=0.1
while True:
ball.dy-=gravity
ball.sety(ball.ycor()+ball.dy)
if ball.ycor()<-300:
ball.dy*=-1