-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjects.java
More file actions
65 lines (53 loc) · 1.52 KB
/
Copy pathObjects.java
File metadata and controls
65 lines (53 loc) · 1.52 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
import acm.graphics.*;
import java.awt.*;
/*
* This is another graphical component and does not do much more than represent a point that is to be avoided
* its main purpose is for the visual aspect of the simulation
*/
public class Objects{
private GOval obj;
private GOval shell;
private EnvironmentV1 myEn;
private double initRadius;
private double myX, myY;
public double distance;
private boolean imClose = false;
public Objects(double x, double y,double d, EnvironmentV1 en){
obj = new GOval(x-d/2, y-d/2, d, d);
obj.setFilled(true);
obj.setFillColor(Color.RED);
shell = new GOval(x-d, y-d, 0, 0);
en.add(obj);
en.add(shell);
myEn = en;
myX = x;
myY = y;
initRadius = d;
}
/**
* returns the distance from an object to the center of this point
*/
public double getDistanceFrom(double xPos, double yPos){
distance = Math.sqrt(Math.pow(xPos-myX,2)+Math.pow(yPos-myY,2))-initRadius;
return distance;
}
public Vector getPosition(){
return new Vector(myX,myY);
}
/*
* This updates the size of the outer shell (used for more graphical representations)
*/
public void updateMyShell(double dist){
myEn.remove(shell);
shell = new GOval(myX-dist-initRadius/2, myY-dist-initRadius/2, 2*dist+initRadius, 2*dist+initRadius);
shell.setFilled(false);
shell.setColor(Color.BLACK);
myEn.add(shell);
}
public boolean close(){
return imClose;
}
public void close(boolean bool){
imClose = bool;
}
}