# Trouble with the bouncing ball example from the NoC book

**URL:** <https://discourse.processing.org/t/trouble-with-the-bouncing-ball-example-from-the-noc-book/13705>\
**Category:** Coding Questions\
**Created:** [August 30, 2019, 2:19pm UTC](https://discourse.processing.org/t/trouble-with-the-bouncing-ball-example-from-the-noc-book/13705 "2019-08-30T14:19:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 31, 2019, 12:27am UTC](https://discourse.processing.org/t/trouble-with-the-bouncing-ball-example-from-the-noc-book/13705/2 "2019-08-31T00:27:58Z")

</div>

picture can be very helpful,  
but for test might need code,  
or here better just link to where you get it from  
[https://github.com/nature-of-code/noc-examples-processing/blob/master/chp01\_vectors/NOC\_1\_1\_bouncingball\_novectors/NOC\_1\_1\_bouncingball\_novectors.pde](https://github.com/nature-of-code/noc-examples-processing/blob/master/chp01_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde) ,

and that version is working here/  
same like the right side of your picture.

now for the left side / the problem /  
again original right:

```auto
  if ((x > width) || (x < 0)) {
    xspeed = xspeed * -1;
  }
  if ((y > height) || (y < 0)) {
    yspeed = yspeed * -1;
  }

```

you have left:

```auto
  if ((x > width || (x < 0)) {
    xspeed = xspeed * -1;
  }
  if ((y > height || (y < 0)) {
    yspeed = yspeed * -1;
  }

```

so you deleted 2 times a ‘)’  
and the red error info ( in the editor and in the console header line )  
says it all.

also please see that the editor has that great feature that it can indicate code blocks  
{ } or ( )  
by posting the cursor ( ? by mouse click ?) behind one see `(|` and see the corresponding as `[)]`

* * *

now you can choose between many coding styles and formatting,  
but one point should be to test if your free form code format  
will survive using the auto format [ctrl][t]

i like following style / for me more easy readable without UNNEEDED (){}

```auto
  if ( x > width || x < 0 ) xspeed *= -1;
  if ( y > height || y < 0 ) yspeed *= -1;

```

so my version of this whole code would look like

```auto
// The Nature of Code / Daniel Shiffman / http://natureofcode.com
// Example 1-1: Bouncing Ball, no vectors

float x = 100, y = 10, xspeed = 2.5, yspeed = 2;

void setup() {
  size(800, 200);
  stroke(0);
  strokeWeight(2);
  fill(127);
}

void draw() {
  background(255);
  if ( ( x += xspeed ) > width || x < 0 ) xspeed *= -1;
  if ( ( y += yspeed ) > height || y < 0 ) yspeed *= -1;
  ellipse(x, y, 48, 48);
}

```

does that look more snappy?

and short is good HA,  
BUT what we should NOT delete is the info where we take it from  
even if would not only legally be required, the book is CC BY NC 3.0  
still for respect keep the AUTHORs name in your code.

( your very first action as a beginner was to delete the first 4 lines of the tutorials code)

---

_[View the full topic](https://discourse.processing.org/t/trouble-with-the-bouncing-ball-example-from-the-noc-book/13705)._
