Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
63 lines (45 loc) · 1.3 KB

File metadata and controls

executable file
·
63 lines (45 loc) · 1.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package inheritance;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class MovingPolygonApp extends PolygonApp {
int maxSpeed;
MovingPolygonApp(int w, int h, boolean tryFSE, int ms) {
super(w, h, tryFSE);
maxSpeed = ms;
}
public void init(int nVertices) {
int width = getWidth();
int height = getHeight();
int[] vx = new int[nVertices];
int[] vy = new int[nVertices];
Random random = getRandom();
int[] x = new int[nVertices];
int[] y = new int[nVertices];
for (int i = 0; i < nVertices; i++) {
x[i] = random.nextInt(width);
y[i] = random.nextInt(height);
vx[i] = 1 + random.nextInt(maxSpeed - 1);
if (random.nextDouble() > 0.5)
vx[i] *= -1;
vy[i] = 1 + random.nextInt(maxSpeed - 1);
if (random.nextDouble() > 0.5)
vy[i] *= -1;
}
setShape(new MovingPolygon(x, y, vx, vy, nVertices));
Color color = new Color(random.nextInt(255), random.nextInt(255),
random.nextInt(255));
getShape().setColor(color);
}
public void draw(Graphics g) {
super.draw(g);
MovingPolygon movingPoly = (MovingPolygon) getShape();
movingPoly.move(0, getWidth(), 0, getHeight());
}
public static void main(String[] args) {
MovingPolygonApp goo = new MovingPolygonApp(500, 500, false, 10);
goo.init(100);
goo.smooth();
goo.go();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.