-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constraint.java
44 lines (34 loc) · 1.12 KB
/
Constraint.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
import java.awt.*;
public class Constraint
{
// the nodes that the constraint is attached to
public Node nodeA;
public Node nodeB;
// the initial length of the constraint
public double length;
// create a new constraint
public Constraint(Node a, Node b)
{
this.nodeA = a;
this.nodeB = b;
// initialize the length to the distance between the nodes
length = PointMath.distance(a.x, a.y, b.x, b.y);
}
// draw the constraint on the screen
public void draw(Graphics g)
{
g.drawLine((int)Math.round(nodeA.x), (int)Math.round(nodeA.y), (int)Math.round(nodeB.x), (int)Math.round(nodeB.y));
}
// Get a color corresponding to a stress percentage (0-1)
/*Color getStressColor(double percent)
{
double inversePercent = 1 - percent;
Color a = Color.RED;
Color b = Color.GREEN;
double red = a.getRed() * percent + b.getRed() * inversePercent;
double green = a.getGreen() * percent + b.getGreen() * inversePercent;
double blue = a.getBlue() * percent + b.getBlue() * inversePercent;
Color result = new Color((int)Math.round(red), (int)Math.round(green), (int)Math.round(blue));
return result;
}*/
}