void setup() {
size(1080,720);
miBol = new Bolita(width/2, height/2, 2, 20, 1, 1, color (0,255,0));
}
void draw() {
background(0);
miBol.move();
miBol.display();
}
class Bolita {
float posX, posY, speed, tam;
int dirX, dirY;
color col;
Bolita (float tposX, float tposY, float tspeed, float ttam, int tdirX, int tdirY, color tcol) {
posX=tposX;
posY=tposY;
speed=tspeed;
tam=ttam;
dirX=tdirX;
dirY=tdirY;
col = tcol;
}
void move() {
posX += speed*dirX;
posY += speed*dirY;
if (posX>width-(tam/2)||posX<tam/2) {
dirX=-dirX;
}
if (posY>height-(tam/2)||posY<tam/2) {
dirY=-dirY;
}
}
void display() {
fill (col);
ellipse(posX, posY, tam, tam);
}
}
No comments:
Post a Comment