Projecting a circle

Hello, i’m trying to create code for when mouse is clicked, a ball is projected (upwards), but as it moves it gradually slows down. So far all i’ve manage to figure out is make it move up and down. I’m a complete beginner so any help would be greatly appreciated.

int ypos;
boolean hitBottom;

void setup(){
  ypos = 0;
  hitBottom = false;

void draw(){

  if (ypos == height){
    hitBottom = true;

  fill(92, 136, 218);
  circle(width/2, ypos, 20);
  if (hitBottom){
  } else {

Hi! Right now you move the circle by changing ypos by +1 or -1. If you modulate this value 1, then you can speed up or slow down the movement. For example, ypos += yspeed and yspeed goes closer to 0 by yspeed = lerp(yspeed, 0, 0.1)

and of course there are many other ways to do it!

1 Like