# Adding wind to bouncing ball example

**URL:** <https://discourse.processing.org/t/adding-wind-to-bouncing-ball-example/8748>\
**Category:** Coding Questions\
**Created:** [February 26, 2019, 8:31pm UTC](https://discourse.processing.org/t/adding-wind-to-bouncing-ball-example/8748 "2019-02-26T20:31:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pieceofcrazy](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@pieceofcrazy](https://discourse.processing.org/u/pieceofcrazy)\
**Post date:** [February 26, 2019, 8:31pm UTC](https://discourse.processing.org/t/adding-wind-to-bouncing-ball-example/8748/1 "2019-02-26T20:31:21Z")

</div>

I’m pretty new to coding and while playing around with the [BouncingBall example](https://processing.org/examples/bouncingball.html) I tried to add some air pushing the ball up if the mouse button in pressed, but it looks really goofy because the ball just goes up in a straight line.  
I don’t really know what could make it lood better.

```auto
PVector location; 
PVector velocity;
PVector gravity; 
PVector wind;

void setup() {
  size(640,360);
  location = new PVector(100,100);
  velocity = new PVector(1.5,2.1);
  gravity = new PVector(0,0.2);
  wind = new PVector(0,0.2);

}

void draw() {
  background(0);
  
  location.add(velocity);
  
  if (mousePressed) {
    velocity.sub(wind);
  } else {
    location.add(velocity);
  }
  velocity.add(gravity);

  if ((location.x > width) || (location.x < 0)) {
    velocity.x = velocity.x * -1;
  }
  if (location.y > height) {

    velocity.y = velocity.y * -0.9; 
    location.y = height;
  }

  stroke(255);
  strokeWeight(2);
  fill(127);
  ellipse(location.x,location.y,48,48);
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 28, 2019, 7:07pm UTC](https://discourse.processing.org/t/adding-wind-to-bouncing-ball-example/8748/2 "2019-02-28T19:07:00Z")

</div>

What, specifically, do you want the wind to do?

Do you want it to blow from where the mouse pointer is? Do you want it to blow up “at random”? Does it gust and die down, or does it blow as long as the mouse is depressed? Describe it more.

You might also be interested a recent related discussion in p5.js: [Bouncing ball hang up (The Nature of Code)](https://discourse.processing.org/t/bouncing-ball-hang-up-the-nature-of-code/8733)
