-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
41 lines (41 loc) · 847 Bytes
/
Shape.java
File metadata and controls
41 lines (41 loc) · 847 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
41
import java.util.Random;
public class Shape {
private double x;
private double y;
private double r;
private double kend;
public Shape(double x,double y){
this.x=x;
this.y=y;
r=10;
Random generator=new Random();
kend=generator.nextDouble()*360;
}
public double getX(){
return x;
}
public void setCordinate(int x,int y){
this.x=x;
this.y=y;
}
public double getY(){
return y;
}
public double getR(){
return r;
}
public void move(){
x+=(10*Math.cos(kend));
y+=(10*Math.sin(kend));
}
public boolean checkBoundaries(double width,double height){
if(x<0||x>width||y>height||y<0) return false;
else return true;
}
public void regenerate(double width,double height){
Random generator=new Random();
kend=generator.nextDouble()*360;
x=generator.nextDouble()*width;
y=generator.nextDouble()*height;
}
}