2025-10-08 12:13:42 +02:00
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
2025-10-08 10:26:19 +02:00
|
|
|
|
|
|
|
|
/**
|
2025-10-08 12:13:42 +02:00
|
|
|
* La classe <code>Dessin</code> gère uniquement le dessin du pendu
|
2025-10-08 10:26:19 +02:00
|
|
|
*
|
2025-10-08 12:13:42 +02:00
|
|
|
* @version 0.1
|
|
|
|
|
* @author Adrien
|
|
|
|
|
* Date : 08-10-2025
|
2025-10-08 10:26:19 +02:00
|
|
|
* Licence :
|
|
|
|
|
*/
|
2025-10-08 12:13:42 +02:00
|
|
|
public class Dessin extends JPanel {
|
2025-10-08 10:26:19 +02:00
|
|
|
|
2025-10-08 12:13:42 +02:00
|
|
|
// --- Constructeur ---
|
|
|
|
|
public Dessin() {
|
|
|
|
|
// Taille préférée pour s'intégrer dans Fenetre
|
|
|
|
|
setPreferredSize(new Dimension(600, 350));
|
|
|
|
|
setBackground(new Color(245, 245, 245));
|
|
|
|
|
}
|
2025-10-08 10:26:19 +02:00
|
|
|
|
2025-10-08 12:13:42 +02:00
|
|
|
// --- Dessin principal ---
|
|
|
|
|
@Override
|
|
|
|
|
protected void paintComponent(Graphics graphics) {
|
|
|
|
|
super.paintComponent(graphics);
|
2025-10-08 10:26:19 +02:00
|
|
|
|
2025-10-08 12:13:42 +02:00
|
|
|
// Anti-aliasing pour des traits plus doux
|
|
|
|
|
Graphics2D graphics2D = (Graphics2D) graphics.create();
|
|
|
|
|
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
|
graphics2D.setStroke(new BasicStroke(3f));
|
|
|
|
|
graphics2D.setColor(Color.DARK_GRAY);
|
|
|
|
|
|
|
|
|
|
// Repères et proportions
|
|
|
|
|
int width = getWidth();
|
|
|
|
|
int height = getHeight();
|
|
|
|
|
int marginPixels = Math.min(width, height) / 12; // marge proportionnelle
|
|
|
|
|
|
|
|
|
|
// Potence : socle
|
|
|
|
|
int baseYCoordinate = height - marginPixels;
|
|
|
|
|
graphics2D.drawLine(marginPixels, baseYCoordinate, width / 2, baseYCoordinate);
|
|
|
|
|
|
|
|
|
|
// Montant vertical
|
|
|
|
|
int postXCoordinate = marginPixels + (width / 12);
|
|
|
|
|
graphics2D.drawLine(postXCoordinate, baseYCoordinate, postXCoordinate, marginPixels);
|
|
|
|
|
|
|
|
|
|
// Traverse horizontale
|
|
|
|
|
int beamLength = width / 3;
|
|
|
|
|
graphics2D.drawLine(postXCoordinate, marginPixels, postXCoordinate + beamLength, marginPixels);
|
|
|
|
|
|
|
|
|
|
// Renfort diagonal
|
|
|
|
|
graphics2D.drawLine(postXCoordinate, marginPixels + height / 10,
|
|
|
|
|
postXCoordinate + width / 12, marginPixels);
|
|
|
|
|
|
|
|
|
|
// Corde
|
|
|
|
|
int ropeXCoordinate = postXCoordinate + beamLength;
|
|
|
|
|
int ropeTopYCoordinate = marginPixels;
|
|
|
|
|
int ropeBottomYCoordinate = marginPixels + height / 12;
|
|
|
|
|
graphics2D.drawLine(ropeXCoordinate, ropeTopYCoordinate, ropeXCoordinate, ropeBottomYCoordinate);
|
|
|
|
|
|
|
|
|
|
// Personnage : tête
|
|
|
|
|
int headRadiusPixels = Math.min(width, height) / 16;
|
|
|
|
|
int headCenterX = ropeXCoordinate;
|
|
|
|
|
int headCenterY = ropeBottomYCoordinate + headRadiusPixels;
|
|
|
|
|
graphics2D.drawOval(headCenterX - headRadiusPixels, headCenterY - headRadiusPixels,
|
|
|
|
|
headRadiusPixels * 2, headRadiusPixels * 2);
|
|
|
|
|
|
|
|
|
|
// Corps
|
|
|
|
|
int bodyTopYCoordinate = headCenterY + headRadiusPixels;
|
|
|
|
|
int bodyBottomYCoordinate = bodyTopYCoordinate + height / 6;
|
|
|
|
|
graphics2D.drawLine(headCenterX, bodyTopYCoordinate, headCenterX, bodyBottomYCoordinate);
|
|
|
|
|
|
|
|
|
|
// Bras
|
|
|
|
|
int armSpanPixels = width / 10;
|
|
|
|
|
int shouldersYCoordinate = bodyTopYCoordinate + height / 24;
|
|
|
|
|
graphics2D.drawLine(headCenterX, shouldersYCoordinate,
|
|
|
|
|
headCenterX - armSpanPixels, shouldersYCoordinate + height / 20);
|
|
|
|
|
graphics2D.drawLine(headCenterX, shouldersYCoordinate,
|
|
|
|
|
headCenterX + armSpanPixels, shouldersYCoordinate + height / 20);
|
|
|
|
|
|
|
|
|
|
// Jambes
|
|
|
|
|
int legSpanPixels = width / 12;
|
|
|
|
|
graphics2D.drawLine(headCenterX, bodyBottomYCoordinate,
|
|
|
|
|
headCenterX - legSpanPixels, bodyBottomYCoordinate + height / 8);
|
|
|
|
|
graphics2D.drawLine(headCenterX, bodyBottomYCoordinate,
|
|
|
|
|
headCenterX + legSpanPixels, bodyBottomYCoordinate + height / 8);
|
|
|
|
|
|
|
|
|
|
graphics2D.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Affichage
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2025-10-08 10:26:19 +02:00
|
|
|
}
|