forked from menault/TD3_DEV51_Qualite_Algo
Fenetre et Dessin v1
This commit is contained in:
@@ -1,23 +1,94 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* La classe <code>Dessin</code>
|
||||
* La classe <code>Dessin</code> gère uniquement le dessin du pendu
|
||||
*
|
||||
* @version
|
||||
* @author
|
||||
* Date :
|
||||
* @version 0.1
|
||||
* @author Adrien
|
||||
* Date : 08-10-2025
|
||||
* Licence :
|
||||
*/
|
||||
public class Dessin {
|
||||
//Attributs
|
||||
public class Dessin extends JPanel {
|
||||
|
||||
//Constructeur
|
||||
public Dessin() {
|
||||
// --- 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));
|
||||
}
|
||||
|
||||
}
|
||||
//Méthodes
|
||||
// --- Dessin principal ---
|
||||
@Override
|
||||
protected void paintComponent(Graphics graphics) {
|
||||
super.paintComponent(graphics);
|
||||
|
||||
//Affichage
|
||||
public String toString() {
|
||||
return "" ;
|
||||
}
|
||||
// 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 "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user