# Projecting a circle

**URL:** <https://discourse.processing.org/t/projecting-a-circle/29379>\
**Category:** Coding Questions\
**Created:** [April 15, 2021, 1:41pm UTC](https://discourse.processing.org/t/projecting-a-circle/29379 "2021-04-15T13:41:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosaria](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@rosaria](https://discourse.processing.org/u/rosaria)\
**Post date:** [April 15, 2021, 1:41pm UTC](https://discourse.processing.org/t/projecting-a-circle/29379/1 "2021-04-15T13:41:25Z")

</div>

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.

```auto
int ypos;
boolean hitBottom;

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

void draw(){
  background(255);

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

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

```

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [April 15, 2021, 2:02pm UTC](https://discourse.processing.org/t/projecting-a-circle/29379/2 "2021-04-15T14:02:53Z")

</div>

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)`

> **[lerp() / Reference](https://processing.org/reference/lerp_.html)**
>
> Calculates a number between two numbers at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the f…

[![](https://img.youtube.com/vi/8uLVnM36XUc/maxresdefault.jpg "Processing / p5.js Tutorial: What is lerp? (Linear Interpolation)") ](https://www.youtube.com/watch?v=8uLVnM36XUc)

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