1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
public class MyView extends View {
public MyView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public MyView(Context context, AttributeSet attrs, int defStyle){super(context, attrs,defStyle);}
public MyView(Context context){super(context);}
// -------------------------- Getter et Setter --------------------------------------
// ** nombre de cercle **
int nbCercle = 21 ;
public int getNbCercle() { return nbCercle; }
public void setNbCercle(int nbCercle) { this.nbCercle = nbCercle; }
// ** épaisseur **
public int epaisseur = 7;
public int getEpaisseur() { return epaisseur; }
public void setEpaisseur(int epaisseur) { this.epaisseur = epaisseur; }
// ==================== Création des cercles ====================
protected void onDraw(Canvas canvas)
{
int x = getWidth(); int y = getHeight(); // hauteur et largeur du téléphone.
Paint paint = new Paint();
//paint.setColor(android.graphics.Color.RED);
paint.setStrokeWidth(epaisseur);
paint.setStyle(Paint.Style.STROKE);
Random rand = new Random();
int n; // taille du cercle
int pX; // position x
int pY; // position y
for(int i=0;i<nbCercle;i++)
{
n = rand.nextInt(300);
pX = rand.nextInt(x);
pY = rand.nextInt(y);
paint.setARGB(255,rand.nextInt(255),rand.nextInt(255),rand.nextInt(255)); // Affecte une couleur.
canvas.drawCircle(pX, pY,n, paint); // Crée un cercle.
}
//canvas.drawLine(0, 0, x, y, paint);
super.onDraw(canvas);
}
} |
Partager