# I have a rectangle which is bouncing on the screen. I want it to occur in 8 steps instead of being continuous

**URL:** https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626
**Category:** Coding Questions
**Tags:** homework
**Created:** [April 10, 2020, 1:24pm UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626 "2020-04-10T13:24:27Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 10, 2020, 1:24pm UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/1 "2020-04-10T13:24:27Z")

</div>

Please help me with this question!!!

---

<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: [April 10, 2020, 2:35pm UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/2 "2020-04-10T14:35:16Z")

</div>

I don’t fully understand

---

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 10, 2020, 3:32pm UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/3 "2020-04-10T15:32:23Z")

</div>

its like rectangle is touches the bottom end of the screen and bounce back to the top and vice versa.  
I want this process to occur in 8 steps instead of being continuous. Like the rectangle should take 8 equal steps from top to botton!!!

---

<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: [April 10, 2020, 3:43pm UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/4 "2020-04-10T15:43:10Z")

</div>

You could add -100 to y and instead of 1

And lower the frameRate()

---

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 11, 2020, 12:47am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/5 "2020-04-11T00:47:53Z")

</div>

without using framerate

---

<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: [April 11, 2020, 1:39am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/6 "2020-04-11T01:39:13Z")

</div>

With a timer then?

Chrisir

---

<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: [April 11, 2020, 2:52am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/7 "2020-04-11T02:52:00Z")

</div>

@bellievr, Not seeing any code or attempt at solution.  
Please read the guidelines regarding asking for help with homework:

[https://discourse.processing.org/faq#homework](https://discourse.processing.org/faq#homework)

---

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 11, 2020, 3:31am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/8 "2020-04-11T03:31:38Z")

</div>

i am not aiming at answer.Its just a help to complete my work…They are not providing me the code.The are just giving instruction

---

<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: [April 11, 2020, 3:53am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/9 "2020-04-11T03:53:47Z")

</div>

However you are not showing any code to help people understand your level of understanding. You are only outlining the problem you have been asked to solve. Please share your thought process if you want help.

---

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 11, 2020, 3:55am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/10 "2020-04-11T03:55:41Z")

</div>

I wish i could but i m not allowed to share my code!!!

---

<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: [April 11, 2020, 4:02am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/11 "2020-04-11T04:02:12Z")

</div>

I see.  
Well, since you can’t share your code, perhaps someone can give you some general advice…  
Or you could outline things you have tried, without the code…

---

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 11, 2020, 4:13am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/12 "2020-04-11T04:13:12Z")

</div>

yes i could outline the things !!  
i have made a rectangle on the top right edge of the screen .  
It moves down and reverses it direction when hits the bottom of the screen  
just like [https://www.youtube.com/watch?v=YIKRXl3wH8Y&feature=emb\_logo](https://www.youtube.com/watch?v=YIKRXl3wH8Y&feature=emb_logo)  
but in this video it moves left to right but in my code it moves top to bottom .  
i just want that it should move in 8 steps from top to bottom instead of being continous…  
Also my rectangle stops when space bar is pressed.

---

<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: [April 11, 2020, 4:26am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/13 "2020-04-11T04:26:25Z")

</div>

And what have you tried in order to solve the problem?  
You only state what you want the final result to be.

---

<div class="post-metadata">

### Author: ![bellievr](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bellievr](https://discourse.processing.org/u/bellievr)
#### Post date: [April 11, 2020, 4:35am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/14 "2020-04-11T04:35:06Z")

</div>

i tried using  
DownCounter=DownCounter%8;  
DownCounter++;  
but doesnt work!!

---

<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: [April 11, 2020, 8:47am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/15 "2020-04-11T08:47:50Z")

</div>

When you have tried something then show your entire code

What’s the y value variable for your rectangle?

say `y=y + (height-20)/8;`

OR with `-` here

---

<div class="post-metadata">

### Author: ![J0R1AN](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/j0r1an/32/7498_2.png) [@J0R1AN](https://discourse.processing.org/u/J0R1AN)
#### Post date: [April 11, 2020, 9:58am UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/16 "2020-04-11T09:58:12Z")

</div>

I think I understand your question and your problem. The `DownCounter` variable you are using right now looks like it should work. With an `if` statement that checks when it is 0, you could move it by one step. The %8 you have there doesn’t mean how many steps, but after how many frames to go up one step. To get the 8 desired steps, maybe use a `step` variable that you set to` height/8` so that it will divide the entire height into steps of 8. If you then just multiply the step variable by -1 when the `Y` value reaches the top or bottom of the screen, it should work.  
I hope this helps, if not, please put the code that isn’t working in your reply, so we can see what you are missing.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [April 11, 2020, 12:18pm UTC](https://discourse.processing.org/t/i-have-a-rectangle-which-is-bouncing-on-the-screen-i-want-it-to-occur-in-8-steps-instead-of-being-continuous/19626/17 "2020-04-11T12:18:09Z")

</div>

Hello,

I encourage you to review the resources available here:

- Processing website has references, examples, tutorials, etc.  
[https://processing.org/](https://processing.org/)

- Those available with the Processing PDE (IDE).  
An exploration of the tabs will reveal what is available; there are libraries and examples there.

- The Processing Foundation  
[https://processingfoundation.org/](https://processingfoundation.org/)  
Check out the tabs.  
In the education tab, there is a reference to the Coding Train.

- The Coding Train  
[https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
[https://thecodingtrain.com/](https://thecodingtrain.com/)

- Happy Coding  
[Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)

To get you started:  
[Examples / Processing.org](https://processing.org/examples/) Check out the section on motion.

`:)`
