48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package linea;
|
|
|
|
import java.awt.BasicStroke;
|
|
import java.awt.Color;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.geom.Arc2D;
|
|
|
|
public class Voiture extends Cercle {
|
|
|
|
// On définit les couleurs directement ici pour simplifier
|
|
private Color couleurArriere = Color.GRAY;
|
|
private Color couleurAvant = Color.GRAY;
|
|
|
|
public Voiture() {
|
|
super();
|
|
this.rayon = 25;
|
|
}
|
|
|
|
@Override
|
|
void Afficher(Graphics g) {
|
|
Graphics2D g2D = (Graphics2D) g;
|
|
g2D.setStroke(new BasicStroke(5.0f));
|
|
|
|
// DESSINER LE DEMI-CERCLE ARRIERE (Au fond)
|
|
g2D.setColor(couleurArriere);
|
|
// Utilisation de rayon*2 pour la largeur et hauteur (cercle parfait)
|
|
g2D.draw(new Arc2D.Double(x - rayon, y - rayon, rayon * 2, rayon * 2, 90, 180, Arc2D.OPEN));
|
|
|
|
// DESSINER LA VOITURE (Au milieu)
|
|
g.setColor(new Color(150, 50, 200));
|
|
g.fillRect((int)x - 20, (int)y - 5, 40, 12);
|
|
|
|
g.setColor(Color.CYAN);
|
|
g.fillRect((int)x - 10, (int)y - 15, 20, 10);
|
|
|
|
g.setColor(Color.DARK_GRAY);
|
|
g.fillOval((int)x - 15, (int)y + 3, 10, 10);
|
|
g.fillOval((int)x + 5, (int)y + 3, 10, 10);
|
|
|
|
g.setColor(Color.YELLOW);
|
|
g.fillOval((int)x + 15, (int)y - 2, 6, 6);
|
|
|
|
// DESSINER LE DEMI-CERCLE AVANT (Par-dessus)
|
|
g2D.setColor(couleurAvant);
|
|
g2D.draw(new Arc2D.Double(x - rayon, y - rayon, rayon * 2, rayon * 2, 90, -180, Arc2D.OPEN));
|
|
}
|
|
} |