-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoids_Scene.java
More file actions
44 lines (33 loc) · 1008 Bytes
/
Boids_Scene.java
File metadata and controls
44 lines (33 loc) · 1008 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
42
43
44
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Dimension;
public class Boids_Scene extends JPanel {
private int[] frameDimensions = new int[2];
private Flock flock;
public Boids_Scene(int[] frameDimensions) {
this.frameDimensions = frameDimensions.clone();
flock = new Flock(frameDimensions);
}
public Dimension getPreferredSize() {
return new Dimension(frameDimensions[0], frameDimensions[1]);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
//center flock
g.translate(frameDimensions[0] / 2, frameDimensions[1] / 2);
flock.draw(g);
}
public void animate() {
int waitTime = 15;
while (true) {
try {
Thread.sleep(waitTime);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
flock.update();
repaint();
}
}
private static final long serialVersionUID = 42l;
}