P5 Python Docs
  • Getting Started
  • Simple mode
  • Reference
    • Shapes
      • 2D
        • point()
        • line()
        • rect()
        • square()
        • triangle()
        • circle()
        • ellipse()
        • arc()
        • quad()
        • beginShape()
      • 3D
        • plane()
        • box()
        • sphere()
        • cone()
        • cylinder()
        • ellipsoid()
        • torus()
    • Controlling the environment
      • coordinateMode()
      • rectMode()
      • ellipseMode()
      • frameRate()
      • setup()
      • draw()
    • Built-in Variables
      • Environment
      • Keyboard
      • Mouse
    • Built-in Functions
      • keyIsDown()
      • millis()
      • second()
      • minute()
      • hour()
      • translate()
      • rotate()
      • createSlider()
      • createGraphics()
      • createVector()
    • Events
      • Keyboard
        • keyPressed()
        • keyReleased()
      • Mouse
        • mouseMoved()
        • mouseDragged()
        • mousePressed()
        • doubleClicked()
        • mouseWheel()
    • Text
      • text()
      • textSize()
      • textAlign()
    • Math
      • drawTickAxes()
      • random()
      • randomGaussian()
      • dist()
      • linmap()
      • bounce()
      • wave()
    • Colour and Outline
      • colorMode()
      • fill()
      • stroke()
      • strokeWeight()
      • background()
    • Images & Audio
      • loadImage() and image()
      • loadSound()
    • 3D Controls
      • orbitControl()
      • translate()
      • rotateZ()
      • rotateX()
      • rotateY()
      • scale()
Powered by GitBook
On this page
  • Example
  • Syntax
  • Description
  1. Reference
  2. Math

bounce()

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

Previouslinmap()Nextwave()

Last updated 2 years ago

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.

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

We'd love to hear your Feedback/Comments .

Strivemath
here