APL/Fun/TestGraphique/FunPanel.java
2022-10-14 17:25:23 +02:00

43 lines
1.4 KiB
Java

import javax.swing.JPanel;
import java.awt.*;
public class FunPanel extends JPanel {
public static double table = 50;
public static int limit = 30;
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());
}
double size = (double)(getWidth() > getHeight() ? getHeight() : getWidth()) / 2.5d;
gg.setColor(Color.BLACK);
for (double i = 0; i < limit; i++) {
double theta = (i / (double)limit) * Math.PI * 2;
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);
}
}
}
}