-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLissajous.java
More file actions
executable file
·77 lines (70 loc) · 2.33 KB
/
Copy pathLissajous.java
File metadata and controls
executable file
·77 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Lissajous extends JPanel {
JTextField aText, bText, deltaText;
double a = 0, b = 0, delta = 0;
int size;
public Lissajous(int size) {
setPreferredSize(new Dimension(size, size));
this.size = size;
aText = new JTextField(5);
aText.setText("5");
bText = new JTextField(5);
bText.setText("2");
deltaText = new JTextField(5);
deltaText.setText("0.7");
setLayout(new FlowLayout());
setBackground(Color.WHITE);
add(new JLabel("a: "));
add(aText);
add(new JLabel("b: "));
add(bText);
add(new JLabel("delta: "));
add(deltaText);
aText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
repaint();
}
});
bText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
repaint();
}
});
deltaText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
repaint();
}
});
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
a = Double.parseDouble(aText.getText());
b = Double.parseDouble(bText.getText());
delta = Double.parseDouble(deltaText.getText());
double X = size / 2 + 2 * size / 5 * Math.sin(delta);
double Y = size / 2 + 2 * size / 5 * Math.cos(0);
for (double t = 0; t <= (a + b) * Math.PI; t += 0.001) {
double nextX = size / 2 + 2 * size / 5 * Math.sin(a * t + delta);
double nextY = size / 2 + 2 * size / 5 * Math.cos(b * t);
int x1 = (int) X;
int y1 = (int) Y;
int x2 = (int) nextX;
int y2 = (int) nextY;
g.drawLine(x1, y1, x2, y2);
X = nextX;
Y = nextY;
}
}
}