Пример #1
0
        /// <summary>
        /// Generates rainfall map given a height map.
        /// </summary>
        /// <param name="heightMap">Height map to base rainfall off of.</param>
        /// <param name="inRules">Rules for how generation is to take place.</param>
        /// <returns>Rainfall map</returns>
        public static double[,,] Run(double[,] heightMap, RainfallMapRules inRules)
        {
            rules = inRules;
            ConstructData();
            var output = new double[2 * rules.xHalfSize, rules.ySize, rules.numberSeasons];

            Parallel.For(0, (rules.numberSeasons), (i) =>
            {
                var yearEffect   = Math.PI * (2 * (i / rules.numberSeasons) - 1);
                var pitchEffect  = Math.Sin(yearEffect) * rules.axisTilt;
                var ITCZone      = BaseITC(heightMap, pitchEffect);
                var pressureMap  = BasePressure(ITCZone, heightMap, yearEffect);
                pressureMap      = SmoothPressure(pressureMap);
                var windMap      = PressureGradient(pressureMap);
                var smallRainMap = RainFlow(windMap, heightMap);
                for (int x = 0; x < 2 * rules.xHalfSize; x++)
                {
                    for (int y = 0; y < rules.ySize; y++)
                    {
                        output[x, y, i] = smallRainMap[x, y];
                    }
                }
            });
            return(output);
        }
Пример #2
0
 /// <summary>
 /// Saves rules to given file location.
 /// </summary>
 /// <param name="fileName">File to save to, not including extension.</param>
 /// <param name="rules">Rules to save.</param>
 public static void Save(string fileName, RainfallMapRules rules)
 {
     using (StreamWriter file = new StreamWriter(fileName + ".xml", false))
     {
         var ruleType   = rules.GetType();
         var serializer = new XmlSerializer(typeof(RainfallMapRules));
         serializer.Serialize(file, rules);
     }
 }