APL/Fun/TestGraphique/FunPanel.java

43 lines
1.4 KiB
Java
Raw Normal View History

2022-10-06 14:58:27 +02:00
import javax.swing.JPanel;
import java.awt.*;
public class FunPanel extends JPanel {
2022-10-14 17:25:23 +02:00
public static double table = 50;
public static int limit = 30;
2022-10-06 14:58:27 +02:00
public FunPanel() {
super();
}
@Override
protected void paintComponent(Graphics g) {
Graphics gg = g.create();
if (this.isOpaque()) {
gg.setColor(getBackground());
gg.fillRect(this.getX(), this.getY(), getWidth(), getHeight());
}
2022-10-14 17:25:23 +02:00
double size = (double)(getWidth() > getHeight() ? getHeight() : getWidth()) / 2.5d;
2022-10-06 14:58:27 +02:00
2022-10-14 17:25:23 +02:00
gg.setColor(Color.BLACK);
2022-10-06 14:58:27 +02:00
for (double i = 0; i < limit; i++) {
double theta = (i / (double)limit) * Math.PI * 2;
2022-10-14 17:25:23 +02:00
gg.fillOval((int)(Math.cos(theta) * size) + getWidth() / 2, (int)(Math.sin(theta) * size) + getHeight() / 2, 6, 6);
for (double j = 0; j < limit; j++) {
double theta2 = (table * j / (double)limit) * Math.PI * 2;
int x1 = (int)(Math.cos(theta) * size) + getWidth() / 2;
int x2 = (int)(Math.cos(theta2) * size) + getWidth() / 2;
int y1 = (int)(Math.sin(theta) * size) + getHeight() / 2;
int y2 = (int)(Math.sin(theta2) * size) + getHeight() / 2;
gg.drawLine(x1 + 3, y1 + 3, x2 + 3, y2 + 3);
}
2022-10-06 14:58:27 +02:00
}
}
}