Beispiel #1
0
    public static void ComputeTemperature(World world, int seed)
    {
        double[,] tempMap = world.GetOrAddMap <double>("temperature");
        int[,] heightMap  = world.GetMap <int>("height");
        int seaLevel     = (int)world.GetProperty("sealevel");
        int equator      = (int)world.GetProperty("equator");
        int planetHeight = (int)world.GetProperty("planetheight");

        //from roughly the hottest and coldest annual temperature, in kelvin
        //-30C to 30C
        double equatorTemp = 303;
        double poleTemp    = 263;
        double tempDistrib = planetHeight / 2.0;

        world.SetProperty("maxtemp", equatorTemp);
        world.SetProperty("mintemp", poleTemp);

        for (int x = 0; x < world.Width; x++)
        {
            for (int y = 0; y < world.Height; y++)
            {
                double newTemp = TerrainGenDemo.Lerp(equatorTemp, poleTemp, Math.Abs(equator - y) / tempDistrib);
                newTemp      -= Math.Max(heightMap[x, y] - seaLevel, 0) * 0.07;
                newTemp       = Math.Max(newTemp, 1);
                tempMap[x, y] = newTemp;
            }
        }
    }
Beispiel #2
0
    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);
            }
        }
    }
Beispiel #3
0
    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);
            }
        }
    }
Beispiel #4
0
    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);
            }
        }
    }
 public Color GetPixelColor()
 {
     if (TreeTropical > 0 && TreeTropical >= TreeConifer && TreeTropical >= TreeDeciduous && TreeTropical >= Grass)
     {
         return(new Color(0, 230, 0, 255));
     }
     if (TreeDeciduous > 0 && TreeDeciduous >= TreeConifer && TreeDeciduous >= Grass)
     {
         return(new Color(50, 180, 50, 255));
     }
     if (TreeConifer > 0 && TreeConifer >= Grass)
     {
         return(new Color(20, 100, 20, 255));
     }
     if (Grass > 0)
     {
         //return new Color(100,200,100,255);
         return(TerrainGenDemo.ColorLerp(new Color(200, 200, 50, 255), new Color(100, 200, 100, 255), Math.Min(Grass / 20.0, 1.0)));
     }
     return(new Color(0, 0, 0, 0));
 }