TP03 ; graphsup proto
This commit is contained in:
@@ -5,6 +5,8 @@ import javax.swing.JFrame;
|
||||
* Fun
|
||||
*/
|
||||
public class Fun {
|
||||
|
||||
private static long time;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -17,14 +19,14 @@ public class Fun {
|
||||
|
||||
frame.setVisible(true);
|
||||
|
||||
while (true) {
|
||||
FunPanel.table += 0.001d;
|
||||
|
||||
p.repaint();
|
||||
try {
|
||||
Thread.sleep(16L);
|
||||
} catch (Exception e) {
|
||||
time = System.nanoTime();
|
||||
|
||||
while (true) {
|
||||
if (System.nanoTime() - time > 16666666L / 10L) {
|
||||
FunPanel.table += 0.0001d;
|
||||
p.repaint();
|
||||
|
||||
time = System.nanoTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,26 @@
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FunPanel extends JPanel {
|
||||
public static double table = 50;
|
||||
public static int limit = 30;
|
||||
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();
|
||||
@@ -19,23 +31,22 @@ public class FunPanel extends JPanel {
|
||||
}
|
||||
|
||||
double size = (double)(getWidth() > getHeight() ? getHeight() : getWidth()) / 2.5d;
|
||||
Point offset = new Point(getX() + getWidth() / 2, getY() + getHeight() / 2);
|
||||
|
||||
gg.setColor(Color.BLACK);
|
||||
for (double i = 0; i < limit; i++) {
|
||||
double theta = (i / (double)limit) * Math.PI * 2;
|
||||
gg.drawString("" + table, 10, 15);
|
||||
|
||||
gg.fillOval((int)(Math.cos(theta) * size) + getWidth() / 2, (int)(Math.sin(theta) * size) + getHeight() / 2, 6, 6);
|
||||
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 = 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user