TP2
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
@@ -9,15 +7,25 @@ import javax.swing.JFrame;
|
||||
public class Fun {
|
||||
|
||||
public static void main(String[] args) {
|
||||
FunPanel p = new FunPanel();
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(100, 100);
|
||||
frame.setSize(700, 700);
|
||||
frame.add(p);
|
||||
FunPanel p = new FunPanel();
|
||||
frame.add(p, BorderLayout.CENTER);
|
||||
|
||||
frame.setVisible(true);
|
||||
p.repaint();
|
||||
|
||||
while (true) {
|
||||
FunPanel.table += 0.001d;
|
||||
|
||||
p.repaint();
|
||||
try {
|
||||
Thread.sleep(16L);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,8 +2,8 @@ import javax.swing.JPanel;
|
||||
import java.awt.*;
|
||||
|
||||
public class FunPanel extends JPanel {
|
||||
private int table = 3;
|
||||
private int limit = 150;
|
||||
public static double table = 50;
|
||||
public static int limit = 30;
|
||||
|
||||
public FunPanel() {
|
||||
super();
|
||||
@@ -18,14 +18,25 @@ public class FunPanel extends JPanel {
|
||||
gg.fillRect(this.getX(), this.getY(), getWidth(), getHeight());
|
||||
}
|
||||
|
||||
double size = (double)getX();
|
||||
System.out.println(size);
|
||||
double size = (double)(getWidth() > getHeight() ? getHeight() : getWidth()) / 2.5d;
|
||||
|
||||
gg.setColor(Color.RED);
|
||||
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) + getX() / 2, (int)(Math.sin(theta) * size) + getY() / 2, 10, 10);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user