APL/Fun/TestGraphique/FunPanel.java
2022-10-20 12:49:09 +02:00

54 lines
1.7 KiB
Java

import javax.swing.JPanel;
import java.awt.*;
import java.util.Random;
public class FunPanel extends JPanel {
public static double table = 0;
public static int limit = 150;
public FunPanel() {
super();
}
private static Point getCirclePoint(double angle, double radius, Point offset) {
Point p = new Point();
p.x = (int)(Math.cos(angle) * radius) + offset.x;
p.y = (int)(Math.sin(angle) * radius) + offset.y;
return p;
}
private static float n = 0;
private static Random r = new Random();
@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;
Point offset = new Point(getX() + getWidth() / 2, getY() + getHeight() / 2);
gg.setColor(Color.BLACK);
gg.drawString("" + table, 10, 15);
for (double i = 1; i <= limit; i++) {
double theta = (i / (double)limit) * Math.PI * 2 - Math.PI / 2 - (Math.PI * 2 / (double)limit);
Point p0 = getCirclePoint(theta, size, offset);
//gg.fillOval(p0.x, p0.y, 6, 6);
//gg.drawString("" + i, p0.x, p0.y);
for (double j = 1; j <= limit; j++) {
double theta2 = (table * i / (double)limit) * Math.PI * 2 - Math.PI / 2 - (Math.PI * 2 / (double)limit);
Point p1 = getCirclePoint(theta2, size, offset);
gg.drawLine(p0.x, p0.y, p1.x, p1.y);
}
}
}
}