# Speed of ball in this code

please format code with </> button * homework policy * asking questions

<
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( dll, dll, width-2dll, height-2dll);
stroke(255); //cut doors
//stroke(255,200,0); // test
for ( int l = 0; l <7; l +=2) rect( dl/2+dl+dll, dl+dll-1, dl/16, dl/16);
for ( int l = 0; l <6; l +=2) rect( dl/2+4dl+dll-2, 2dl+dll-1, dl/16, dl/16);
stroke(labcol); // blocks
//stroke(255,200,0); // test
rect(dl/2+3dl,dl/2+1dl-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

Here:

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

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

Chrisir

1 Like