bounce()

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

Example

def draw():
  ...  
  y = bounce(0,height,10)
  circle(200,y,20)

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

Syntax

bounce(edge1, edge2, speed)
Input
Description

edge1

value for the start/first limit of the motion

edge2

value for the end/second limit of the motion

speed

the speed of motion

Description

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.

circle-info

Find these documents helpful? Let the people who made them help your child learn to code at Strivematharrow-up-right!

We'd love to hear your Feedback/Comments herearrow-up-right.

Last updated