-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDot.java
More file actions
executable file
·40 lines (37 loc) · 805 Bytes
/
Dot.java
File metadata and controls
executable file
·40 lines (37 loc) · 805 Bytes
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
public class Dot
{
private static final int MAXDX=2;
private static final int MAXDY=2;
private double x;
private double y;
private double dx;
private double dy;
public Dot()
{
x=0.0;
y=0.0;
dx=0.0;
dy=0.0;
}
public int getX() { return (int)(x+0.5); }
public int getY() { return (int)(y+0.5); }
/**
* TODO: Randomize somewhat.
*/
public void updateDot(int targetX, int targetY) {
// System.out.print("Was: "+x+","+y);
dx += (targetX-x)*0.1;
if(Math.abs(dx)>MAXDX) {
dx = Math.abs(dx)/dx*MAXDX;
}
dx += Math.random()*4-2;
dy += (targetY-y)*0.1;
if(Math.abs(dy)>MAXDY) {
dy = Math.abs(dy)/dy*MAXDY;
}
dy += Math.random()*4-2;
x += dx;
y += dy;
// System.out.println(" is: "+x+","+y);
}
}