-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorldPanel.java
More file actions
executable file
·59 lines (50 loc) · 1.44 KB
/
WorldPanel.java
File metadata and controls
executable file
·59 lines (50 loc) · 1.44 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
import javax.swing.*;
import java.awt.*;
public class WorldPanel extends JPanel {
World world;
int size;
int pointSize;
int canvasWidth;
public WorldPanel(World w) {
world = w;
size = world.size;
pointSize =(int)((double) Simulator.FRAME_WIDTH / size);
canvasWidth = size * pointSize;
setOpaque(true);
setBackground(Color.black);
setPreferredSize(new Dimension(canvasWidth, canvasWidth));
}
@Override
protected void paintComponent(Graphics g) {
//*
g.setColor(Color.black);
g.fillRect(0, 0, getWidth(), getHeight());
for (Being b : world.beings) {
if (b == null || b.dead) continue;
drawBeing(b, g);
}/*/
testDrawHostility(g);
//*/
validate();
}
public void drawBeing(Being b, Graphics g) {
try {
g.setColor(new Color((float) b.strength, (float) b.fertility, (float) b.intelligence));
} catch(IllegalArgumentException e) {
System.out.println(b);
}
g.fillRect(adjust(b.x), adjust(b.y), pointSize, pointSize);
}
public void testDrawHostility(Graphics g) {
for (int i = 0; i < world.hostility.length; i++) {
for (int j = 0; j < world.hostility[i].length; j++) {
g.setColor(new Color(world.hostility[i][j],world.hostility[i][j],
world.hostility[i][j]));
g.fillRect(adjust(i), adjust(j), pointSize, pointSize);
}
}
}
public int adjust(int location) {
return location * pointSize;
}
}