-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cord.java
56 lines (49 loc) · 1.36 KB
/
Cord.java
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
import java.awt.Graphics;
import java.awt.Color;
public class Cord
{
public static final Color CORD_COLOR;
public static final int CORD_PIVOT_X = 250;
public static final int CORD_PIVOT_Y = 20;
public static final double MIN_DIVISIONS = 60.0;
public int length;
public double angle;
public double fastestSpeed;
Pendulum p;
Cord(final Pendulum pen) {
super();
this.length = 10;
this.angle = 0.0;
this.p = pen;
this.fastestSpeed = 20.0;
}
public void newLength(final int x, final int y) {
final double sqx = (250 - x) * (250 - x);
final double sqy = (20 - y) * (20 - y);
final double len = Math.sqrt(sqx + sqy);
this.length = (int)len;
this.newAngle(x);
}
public void newAngle(final int x) {
final double opp = x - 250;
if (Math.abs(opp) < 1.0) {
this.angle = 0.0;
}
else {
this.angle = Math.asin(opp / this.length);
}
}
public double getDivisions() {
if (this.length < 60.0) {
return 60.0;
}
return this.length;
}
public void draw(final Graphics g) {
g.setColor(Cord.CORD_COLOR);
g.drawLine(250, 20, this.p.weight.xpos, this.p.weight.ypos);
}
static {
CORD_COLOR = Color.black;
}
}