-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
210 lines (96 loc) · 3.15 KB
/
Circle.java
File metadata and controls
210 lines (96 loc) · 3.15 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Represents a circle
import java.awt.*;
import java.util.Random;
public class Circle{
private int centerX, centerY, radius;
private Color color;
private int direction, speed;
private boolean filled;
private Random gen;
//public Circle(int x, int y, int r, Color c){
public Circle(int x, int y, int r){
centerX = x;
centerY = y;
radius = r;
color = Color.black;
direction = 0;
speed = 0;
filled = false;
gen = new Random();
}
public void draw(Graphics g){
Color oldColor = g.getColor();
g.setColor(color);
// Translates circle's center to rectangle's origin for drawing.
if (filled)
g.fillOval(centerX - radius, centerY - radius, radius * 2, radius * 2);
else
g.drawOval(centerX - radius, centerY - radius, radius * 2, radius * 2);
g.setColor(oldColor);
}
public void fill(Graphics g){
Color oldColor = g.getColor();
g.setColor(color);
// Translates circle's center to rectangle's origin for drawing.
g.fillOval(centerX - radius, centerY - radius, radius * 2, radius * 2);
g.setColor(oldColor);
}
public boolean containsPoint(int x, int y){
int xSquared = (x - centerX) * (x - centerX);
int ySquared = (y - centerY) * (y - centerY);
int radiusSquared = radius * radius;
return xSquared + ySquared - radiusSquared <= 0;
}
public void move(int xAmount, int yAmount){
centerX = centerX + xAmount;
centerY = centerY + yAmount;
}
public void setColor(){
int red = gen.nextInt(256);
int green = gen.nextInt(256);
int blue = gen.nextInt(256);
color = new Color(red, green, blue);
}
public int getRadius(){
return radius;
}
public void setRadius(){
//set random radius here at 10 min
radius = gen.nextInt(31) + 10;
}
public int getX(){
return centerX;
}
public int getY(){
return centerY;
}
public void setY(){
centerY = 0 - radius;
}
public int getDirection(){
return direction;
}
public void setSpeed(){
speed = gen.nextInt(6) + 5;
//speed = 1; //for testing
}
public void setDirection(int d){
direction = d % 360;
}
public void turn(int degrees){
direction = (direction + degrees) % 360;
}
// Moves the circle in the current direction using its
// current speed
public void move(){
move((int)(speed * Math.cos(Math.toRadians(direction))),
(int)(speed * Math.sin(Math.toRadians(direction))));
}
public void moveScreen(){
move((int)(speed * Math.cos(Math.toRadians(direction))),
(int)(-1 * speed * Math.sin(Math.toRadians(direction))));
}
public void setFilled(boolean b){
filled = b;
}
}