Returns a value that varies back and forth between 2 given limits with time. The movement is linear.


def draw():
  y = bounce(0,height,10)
def draw():
  y = bounce(0,height,10)
  x = x + 1


bounce(edge1, edge2, speed)


value for the start/first limit of the motion


value for the end/second limit of the motion


the speed of motion


The bounce function provides a method for generating a value that changes or "varies" over time between two specific values: edge1 and edge2.

edge1 and edge2 act as boundaries. edge1 represents the smallest value that can be returned, and edge2 represents the largest. The function will consistently generate a new value that is somewhere between these two boundaries.

The rate at which this value changes is determined by the speed parameter. A higher speed will cause the value to change more rapidly between edge1 and edge2, while a lower speed will cause it to change more slowly.

This function is useful for cases where you need a value that continuously adjusts within a specific range, such as for animations, simulations, or other dynamic processes.

Find these documents helpful? Let the people who made them help your child learn to code at Strivemath!

We'd love to hear your Feedback/Comments here.

Last updated