forked from kelsey-sorrels/processingworldbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorldSnapShot.java
81 lines (73 loc) · 1.95 KB
/
WorldSnapShot.java
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
import java.util.List;
import processing.core.PApplet;
class WorldSnapShot
{
// Height of world
float[][] world;
// Height of water
float[][] water;
// Height of snow.
float[][] snow;
// Mass of water vapor.
float[][] waterVapor;
// Amount of vegetation
float[][] vegetation;
// People in the world
List<Citizen> citizens;
// Cities of the world
List<City> cities;
public WorldSnapShot
(
final float[][] world,
final float[][] water,
final float[][] snow,
final float[][] waterVapor,
float[][] vegetation,
List<Citizen> citizens,
List<City> cities
)
{
this.world = world;
this.water = water;
this.snow = snow;
this.waterVapor = waterVapor;
this.vegetation = vegetation;
this.citizens = citizens;
this.cities = cities;
}
public float getWorld(float x, float y)
{
return world[(int)(x * world[0].length)][(int)(y * world.length)];
}
public float getWater(float x, float y)
{
return water[(int)(x * water[0].length)][(int)(y * water.length)];
}
public float getSnow(float x, float y)
{
return snow[(int)(x * snow[0].length)][(int)(y * snow.length)];
}
public float getWaterVapor(float x, float y)
{
return waterVapor[(int)(x * waterVapor[0].length)][(int)(y * waterVapor.length)];
}
public float getVegetation(float u, float v)
{
int x = (int)(u * vegetation[0].length);
int y = (int)(v * vegetation.length);
float vo = vegetation[x][y];
float ve = vegetation[PApplet.constrain(x + 1, 0, vegetation[0].length-1)][y];
float vw = vegetation[PApplet.constrain(x - 1, 0, vegetation[0].length-1)][y];
float vs = vegetation[x][PApplet.constrain(y + 1, 0, vegetation.length-1)];
float vn = vegetation[x][PApplet.constrain(y - 1, 0, vegetation.length-1)];
return (vo+ve+vw+vs+vn)/5;
}
public List<Citizen> getCitizens()
{
return citizens;
}
public List<City> getCities()
{
return cities;
}
}