# How do I move ball shape from corner to corner?

**URL:** <https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 9, 2022, 12:38am UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087 "2022-12-09T00:38:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilhxmun](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@ilhxmun](https://discourse.processing.org/u/ilhxmun)\
**Post date:** [December 9, 2022, 12:38am UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/1 "2022-12-09T00:38:11Z")

</div>

Hi, I need to make a program in processing where a ball moves from each corner of the screen to the other. I keep getting stuck at the 3rd corner.  
Another option for my assignment is making a ball grow bigger as it moves from one corner to another. I’m in a very tight time crunch so an answer asap would be very appreciated! :))

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 9, 2022, 2:11am UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/2 "2022-12-09T02:11:23Z")

</div>

> [@ilhxmun](#):
>
> I keep getting stuck at the 3rd corner.

Show me your code please

---

<div class="post-metadata">

**Author:** ![ilhxmun](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@ilhxmun](https://discourse.processing.org/u/ilhxmun)\
**Post date:** [December 9, 2022, 2:57am UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/3 "2022-12-09T02:57:59Z")

</div>

I’m sorry, I lost it. I’m not sure how but I think when my little brother got ahold of my computer. Currently trying to redo it but I can’t remember where I left off.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 9, 2022, 8:58am UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/4 "2022-12-09T08:58:27Z")

</div>

Alright

- You have a ball position

- You add the ball speed to it to make it move

- Make a counter for the corners and increment it when you reach a corner

Depending upon the counter set the **speed**

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [December 9, 2022, 12:40pm UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/5 "2022-12-09T12:40:56Z")

</div>

Hi

Control ball moving and direction

[https://funprogramming.org/15-Ball-bouncing-at-the-window-borders.html](https://funprogramming.org/15-Ball-bouncing-at-the-window-borders.html)

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [December 11, 2022, 5:58pm UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/6 "2022-12-11T17:58:53Z")

</div>

Greetings @ilhxmun 🙂

Welcome to the forum!

Just a gentle note:

“Help with a simple program” is a very general description of your question.

I have retitled your topic to match the question in your post.  
This will help others who come to the forum in the future with the same/or similar question to search for and find an answer.

If you feel the revised title does not reflect your question, of course, change it to your liking (using descriptive keywords!). 🙂

🤓

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 11, 2022, 8:23pm UTC](https://discourse.processing.org/t/how-do-i-move-ball-shape-from-corner-to-corner/40087/7 "2022-12-11T20:23:44Z")

</div>

here is an example

- in addition to my post above

```auto

// 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GLOBAL VARIABLES

int ballX;
int ballY;

int ballXadd=3; 
int ballYadd=3; 

color bkCol; 

void setup() { ///////////////// SET-UP STARTS

  size(300, 300);

  ballX= 0;
  ballY= 0;

  bkCol= 255;
} ///// SET-UP CLOSE

void draw() { ////// DRAW LOOP START

  background (bkCol);

  fill(255, 0, 0); 
  ellipse(ballX, ballY, 6, 6);

  ballX+=ballXadd; 
  ballY+=ballYadd;

  if (dist(ballX, ballY, width, height) < 12) {
    bkCol=111;
  }
} /////// DRAW LOOP CLOSE
//

```
