Cours:BallePOO

De troyesGEII
Aller à : navigation, rechercher

Première version

class Balle
{
  float rayon;
  PVector position;
  color couleur;
  
  Balle(float r, PVector p)
  {
    rayon = r;
    position = p;
    couleur = color(100,0,0);
  }

  Balle(float r, PVector p, color c)
  {
    this(r,p);
    couleur = c;
  }
  
  void afficher()
  {
    fill(couleur);
    ellipse(position.x,position.y,2*rayon,2*rayon);
  }
}


Balle b1,b2;


void setup()
{
  float r = 10;
  PVector p;
  p = new PVector(15,20);
  b1 = new Balle(r,p);
  color c;
  c = color(0,100,0);
  p = new PVector(40,40);
  b2 = new Balle(r,p,c);
}


void draw()
{
 b1.afficher();
 b2.afficher();
}