# Speed of ball in this code

**URL:** <https://discourse.processing.org/t/speed-of-ball-in-this-code/36111>\
**Category:** Coding Questions\
**Created:** [April 4, 2022, 6:10am UTC](https://discourse.processing.org/t/speed-of-ball-in-this-code/36111 "2022-04-04T06:10:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonjaminbanjer](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@bonjaminbanjer](https://discourse.processing.org/u/bonjaminbanjer)\
**Post date:** [April 4, 2022, 6:10am UTC](https://discourse.processing.org/t/speed-of-ball-in-this-code/36111/1 "2022-04-04T06:10:07Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

\<  
Ball b;  
color labcol = color(200, 0, 0);

void setup() {  
size(600, 600);  
b = new Ball(width /120, height/500, 15);  
}

void draw() {  
background(255);  
draw\_lab();  
b.render();  
}

class Ball {  
boolean goUP, goDOWN, goLEFT, goRIGHT;  
int x, y, r;  
Ball(int x\_, int y\_, int r\_) {  
x = x\_;  
y = y\_;  
r = r\_;  
}  
void render() {  
if ((keyPressed == true) && (key == CODED)) {  
color\_check();  
if (keyCode == UP && goUP ) y–;  
if (keyCode == DOWN && goDOWN ) y++;  
if (keyCode == LEFT && goLEFT ) x–;  
if (keyCode == RIGHT && goRIGHT ) x++;  
}  
fill(100, 200, 0);  
stroke(100,200, 0);  
strokeWeight(1);  
ellipse(x, y, r, r);  
}  
void color\_check() {  
goUP=goDOWN=goLEFT=goRIGHT=true;  
if ( labcol == get(x, y-r/2 -1) ) goUP = false;  
if ( labcol == get(x, y+r/2 +1) ) goDOWN = false;  
if ( labcol == get(x-r/2 -1, y) ) goLEFT = false;  
if ( labcol == get(x+r/2 +1, y) ) goRIGHT = false;  
}  
}

void draw\_lab() {  
int dl=40;  
noFill();  
stroke(labcol);  
strokeWeight(1);  
rect(1,1,width-2,height-2);  
strokeWeight(dl/2);  
for ( int l = 1; l \<8; l++) rect( dl_l, dl_l, width-2_dl_l, height-2_dl_l);  
stroke(255); //cut doors  
//stroke(255,200,0); // test  
for ( int l = 0; l \<7; l +=2) rect( dl/2+dl+dl_l, dl+dl_l-1, dl/16, dl/16);  
for ( int l = 0; l \<6; l +=2) rect( dl/2+4_dl+dl_l-2, 2_dl+dl_l-1, dl/16, dl/16);  
stroke(labcol); // blocks  
//stroke(255,200,0); // test  
rect(dl/2+3_dl,dl/2+1_dl-1, dl/16, dl/16);  
// more  
}

> 

I have this code and would like to change the speed of the ellipse so it is faster, how do i do that

---

<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 4, 2022, 8:18am UTC](https://discourse.processing.org/t/speed-of-ball-in-this-code/36111/2 "2022-04-04T08:18:41Z")

</div>

Here:

> [@bonjaminbanjer](#):
>
> if (keyCode == UP && goUP ) y–;  
> if (keyCode == DOWN && goDOWN ) y++;  
> if (keyCode == LEFT && goLEFT ) x–;  
> if (keyCode == RIGHT && goRIGHT ) x++;

`--` and `++` subs or adds 1.

instead say `y-=3;` for example (short for `y = y - 3;` by the way)

Chrisir
