Creating a Simple class with a circle

Hello, I am trying to make a class with just a simple circle. I am planning to eventually have more circles too, but I think that I am running into a syntax/logic error. Any help would be greatly appreciated.

bubble b1;
void setup(){
size(300,400);
b1 = new bubble(10,30,10,10);
}

void draw(){
background(255);
b1.display();
}

class bubble{
float x;
float y;
float dx;
float dy;

bubble(float x, float y, float dx, float dy){
this.x=x;
this.y=y;
this.dx=dx;
this.dy=dy;
}
}

void display(){
fill(0);
ellipse(random(0,width-30),height-30, 30,30);
}

1 Like

Hi remember to use control + shift + c to format code.

Your code is fine, its just the final display function is not inside your class.

3 Likes

Use ctrl-t in the processing ide (not the forum) to get auto-indent.

Then you can spot when it’s not in the class.

Also in display () you don’t use x,y and dx,dy

1 Like

when you are planning to use 4 or more bubbles look at array or ArrayList please.

It’s a list of bubbles you can have automatically loops over.