funkier functions that make you look smart

We can also use an exponential function, which starts off really slow and gradually moves faster and faster.

//----------------------------
// variables
float currY;
int currTime;

//---------------------------- 
void setup() {
  // set up the applet
  size(300, 300);
  smooth();
  frameRate(30);

  // reset the animation independent variable (time)
  currTime = 0;  

  // set the ball color
  noStroke();
  fill(#FF6F00);
}

//----------------------------
void draw() {
  // clear the screen
  background(0);

  // move the ball
  currY = move(currTime);

  // draw the ball  
  ellipse(width/2, currY, 20, 20);

  currTime++;
}

//----------------------------
void mousePressed() {
  // reset the animation independent variable (time)
  currTime = 0;  
}

//----------------------------
float move(float x) {
  return (pow(1.1, x) + 10);
}

Finally, we can try a logarithmic function, which starts off really fast and gradually moves slower and slower.

//----------------------------
float move(float x) {
  return (50 * log(x) + 10);
}

Remember that with all of these functions, you can always add a coefficient or a constant term to scale or offset your output!

Math For Artists Who Now Need to Program

Elie Zananiri
ITP DriveBy
1 Oct 2008