public static void TempImage(World world, Image img) { double[,] tempMap = world.GetMap <double>("temperature"); Tuple <double, double> bounds = TerrainGenDemo.ArrayBounds2D(tempMap); double minTemp = bounds.Item1; double maxTemp = bounds.Item2; //int maxTemp = (int)world.GetProperty("maxtemp"); //int minTemp = (int)world.GetProperty("mintemp"); double tempDif = maxTemp - minTemp; Color hotColor = new Color(255, 0, 0, 150); Color coldColor = new Color(255, 0, 0, 0); for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { double t = (tempMap[x, y] - minTemp) / tempDif; Color pixCol = TerrainGenDemo.ColorLerp(coldColor, hotColor, t); img.SetPixel((uint)x, (uint)y, pixCol); } } }
public static void HeightShadeImage(World world, Image img) { int[,] heightMap = world.GetMap <int>("height"); Tuple <int, int> heightMinMax = TerrainGenDemo.ArrayBounds2D(heightMap); int heightMin = heightMinMax.Item1; int heightMax = heightMinMax.Item2; int heightRange = heightMax - heightMin; int heightMedian = (int)(heightMin + (heightRange * 0.5)); int seaLevel = (int)world.GetProperty("sealevel"); for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { Color col; int height = heightMap[x, y]; int depth = heightMax - height; /* * int slope = x < world.Width-1 ? heightMap[x+1,y] - height : 0; * int slopeAlpha = Math.Min(Math.Abs(slope)*5, 255); * byte slopeByte = (byte)slopeAlpha; * if (slope > 0) * { * col = new Color(255,255,255,slopeByte); * } * else * { * col = new Color(0,0,0,slopeByte); * } */ double alphaFactor = 0.0; if (height > seaLevel) { col = new Color(255, 255, 255, 0); alphaFactor = (double)(height - seaLevel) / (heightMax - seaLevel); } else { col = new Color(0, 0, 0, 0); alphaFactor = (double)(seaLevel - height) / (seaLevel - heightMin); } double maxAlpha = 200.0; double rawAlpha = alphaFactor * maxAlpha; col.A = (byte)rawAlpha; img.SetPixel((uint)x, (uint)y, col); } } }
public static void ComputeFitness(World world, int seed) { double[,] tempMap = world.GetMap <double>("temperature"); int[,] moistureMap = world.GetMap <int>("moisture"); VegetationFitness[,] fitnessMap = world.GetOrAddMap <VegetationFitness>("fitness"); Tuple <int, int> moistureMinMax = TerrainGenDemo.ArrayBounds2D <int>(moistureMap); for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { double temperature = tempMap[x, y]; double moisture = moistureMap[x, y]; fitnessMap[x, y].Generate(temperature, moisture); } } }