We are about to switch to a new forum software. Until then we have removed the registration on this forum.
When I run the code there should be two balls moving, but it only shows one ball. I'm sure it's a dumb mistake, but I haven't been able to figure it out.
circulo c;
circulo c1;
void setup(){
size(700,500);
c = new circulo(30,width-1,0,2,3);
c1 = new circulo(25,0,height/2,4,5);
}
void draw(){
background(255);
c.move();
c.display();
c1.move();
c1.display();
}
class circulo{
float x;
float velocidadX;
float velocidadY;
float y;
float d;
circulo(float diametro, float posX, float posY, float vx, float vy){
d = diametro;
x = posX;
y = posY;
velocidadX = vx;
velocidadY = vy;
}
void move(){
y = y + velocidadY;
x = x + velocidadX;
if (x > width){
velocidadX = -velocidadX;
}
if (x < 0){
velocidadX = -velocidadX;
}
if (y > height){
velocidadY= -velocidadY;
}
if (y < 0){
velocidadY= -velocidadY;
}
}
void display(){
background(10);
ellipse(x, y, d, d);
}
}
`
Answers
background() erases everything that has been drawn before! L-)
And you've got background() inside your method display()! #-o
BtW, classes and interfaces should follow the UpperCaseNaming convention. ~O)
So class circulo should be renamed as Circulo. ;)