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
·
76 lines (56 loc) · 1.61 KB

File metadata and controls

executable file
·
76 lines (56 loc) · 1.61 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
64
65
66
67
68
69
70
71
72
73
74
75
76
package abstractclassesandinterfaces;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Random;
import goo.Goo;
public class App extends Goo {
ArrayList<Moveable> movingObjects;
ArrayList<Drawable> drawingObjects;
Random random;
public App(int w, int h) {
super(w, h);
random = new Random();
movingObjects = new ArrayList<Moveable>();
drawingObjects = new ArrayList<Drawable>();
int nVertices = 10;
int maxSpeed = 10;
int width = getWidth();
int height = getHeight();
int[] x = new int[nVertices];
int[] y = new int[nVertices];
int[] vx = new int[nVertices];
int[] vy = 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;
}
MovingPolygon poly = new MovingPolygon(x, y, vx, vy, nVertices);
Color color = new Color(random.nextInt(255), random.nextInt(255),
random.nextInt(255));
poly.setColor(color);
drawingObjects.add(poly);
movingObjects.add((Moveable)poly);
Message drawString = new Message("You are watching a moving polygon", 50);
drawingObjects.add(drawString);
}
public void draw(Graphics g) {
for (Drawable obj : drawingObjects) {
obj.draw(g);
}
for (Moveable obj : movingObjects) {
obj.move(0, getWidth(), 0, getHeight());
}
}
public static void main(String[] args) {
Goo goo = new App(500, 500);
goo.smooth();
goo.go();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.