-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcenter.java
More file actions
68 lines (53 loc) · 1.1 KB
/
Copy pathcenter.java
File metadata and controls
68 lines (53 loc) · 1.1 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
import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;
public class center {
ArrayList<point> mypoints = new ArrayList<point>();
private double x, y;
Color c;
public center(Color c) {
this.c = c;
x = 50 + getRand();
y = 700 - getRand();
}
public void clearPoints() {
mypoints = new ArrayList<point>();
}
public void addPoint(point p) {
mypoints.add(p);
}
public void calculateNextPos() {
if (mypoints.size() == 0) {
return;
}
double allx = 0;
double ally = 0;
for (int i=0; i<mypoints.size(); i++) {
point p = mypoints.get(i);
allx += p.x();
ally += p.y();
}
x = allx/mypoints.size();
y = ally/mypoints.size();
}
public double calculateDistortion() { // ADD ALL DISTORTION
double distortion = 0;
for (int i=0; i<mypoints.size(); i++) {
distortion += mypoints.get(i).getDist();
}
return distortion;
}
public int getRand() {
Random rand = new Random();
return rand.nextInt(500) + 50;
}
public int x() {
return (int) x;
}
public int y() {
return (int) y;
}
public Color color() {
return c;
}
}