2022-10-06 14:58:27 +02:00
|
|
|
import javax.swing.JPanel;
|
|
|
|
import java.awt.*;
|
2022-10-20 12:49:09 +02:00
|
|
|
import java.util.Random;
|
2022-10-06 14:58:27 +02:00
|
|
|
|
|
|
|
public class FunPanel extends JPanel {
|
2022-10-20 12:49:09 +02:00
|
|
|
public static double table = 0;
|
|
|
|
public static int limit = 150;
|
2022-10-06 14:58:27 +02:00
|
|
|
|
|
|
|
public FunPanel() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2022-10-20 12:49:09 +02:00
|
|
|
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();
|
|
|
|
|
2022-10-06 14:58:27 +02:00
|
|
|
@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-20 12:49:09 +02:00
|
|
|
Point offset = new Point(getX() + getWidth() / 2, getY() + getHeight() / 2);
|
2022-10-06 14:58:27 +02:00
|
|
|
|
2022-10-14 17:25:23 +02:00
|
|
|
gg.setColor(Color.BLACK);
|
2022-10-20 12:49:09 +02:00
|
|
|
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);
|
2022-10-06 14:58:27 +02:00
|
|
|
|
2022-10-20 12:49:09 +02:00
|
|
|
//gg.fillOval(p0.x, p0.y, 6, 6);
|
|
|
|
//gg.drawString("" + i, p0.x, p0.y);
|
2022-10-14 17:25:23 +02:00
|
|
|
|
2022-10-20 12:49:09 +02:00
|
|
|
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);
|
2022-10-14 17:25:23 +02:00
|
|
|
}
|
2022-10-06 14:58:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|