public static void RunPathScenario() { IField2d <float> costs = new MountainNoise(1024, 1024, 0.01f);// new Transformation2d(new Simplex2D(1024, 1024, 0.1f), v => (float)Math.Round(v)); var path = Search.FindPath(new Rectangle(0, 0, costs.Width, costs.Height), new DemiurgeLib.Common.Point2d(10, 10), new DemiurgeLib.Common.Point2d(costs.Width - 10, costs.Height - 10), (a, b) => { if (a.x < 0 || b.x < 0 || a.y < 0 || b.y < 0 || a.x >= costs.Width || b.x >= costs.Width | a.y >= costs.Height || b.y >= costs.Height) { return(float.PositiveInfinity); } float cost = Point2d.Distance(a, b); cost += (float)Math.Pow(1000f * Math.Abs(costs[a.y, a.x] - costs[b.y, b.x]), 2); // Steep slope penalty. cost += 100f * costs[b.y, b.x]; // High altitude penalty. return(cost); }); Bitmap bmp = new Bitmap(costs.Width, costs.Height); for (int y = 0; y < costs.Height; y++) { for (int x = 0; x < costs.Width; x++) { bmp.SetPixel(x, y, Color.FromArgb((int)(255 * costs[y, x]), (int)(255 * costs[y, x]), (int)(255 * costs[y, x]))); } } bmp.Save("C:\\Users\\Justin Murray\\Desktop\\mountains.png"); foreach (var pnt in path) { bmp.SetPixel(pnt.x, pnt.y, Color.Red); } bmp.Save("C:\\Users\\Justin Murray\\Desktop\\path_test.png"); }
public static void RunMountainousScenario(int width, int height, float startingScale) { string input = "C:\\Users\\Justin Murray\\Desktop\\maps\\input\\rivers.png"; Bitmap jranjana = new Bitmap(input); //int needToMake = 0; //for (int x = 0, y = 0; y < jranjana.Height / 24; y += ++x / (jranjana.Width / 24), x %= (jranjana.Width / 24)) //{ // if (24 * x + 23 <= jranjana.Width && 24 * y + 23 <= jranjana.Height) // { // for (int j = 24 * y; j < 24 * y + 24; j++) // { // for (int i = 24 * x; i < 24 * x + 24; i++) // { // if (jranjana.GetPixel(i, j).GetBrightness() > 0.3f) // { // needToMake++; // i += 24; // j += 24; // } // } // } // } //} //System.Console.WriteLine("Have to make " + needToMake); long seed = System.DateTime.Now.Ticks; IField2d <float> mountainNoise0 = new MountainNoise(width, height, startingScale, seed, 0, 0); //IField2d<float> mountainNoise1 = new MountainNoise(width, height, startingScale, seed, 1024, 0); //IField2d<float> mountainNoise2 = new MountainNoise(width, height, startingScale, seed, 0, 1024); //IField2d<float> mountainNoise3 = new MountainNoise(width, height, startingScale, seed, 1024, 1024); //IField2d<float> valleyNoise = new Transformation2d(mountainNoise, (x, y, val) => //{ // float t = Math.Min(1f, Math.Abs(mountainNoise.Width / 2 - x) / 100f); // return val * t; //}); Utils.OutputField(mountainNoise0, new Bitmap(width, height), "C:\\Users\\Justin Murray\\Desktop\\m0.png"); //var scaled = new ReResField(new SubField<float>(new Utils.FieldFromBitmap(jranjana), new Rectangle(400, 300, 200, 200)), 5f); //Utils.OutputField(scaled, new Bitmap(scaled.Width, scaled.Height), "C:\\Users\\Justin Murray\\Desktop\\scaled.png"); //Utils.OutputField(mountainNoise1, new Bitmap(width, height), "C:\\Users\\Justin Murray\\Desktop\\m1.png"); //Utils.OutputField(mountainNoise2, new Bitmap(width, height), "C:\\Users\\Justin Murray\\Desktop\\m2.png"); //Utils.OutputField(mountainNoise3, new Bitmap(width, height), "C:\\Users\\Justin Murray\\Desktop\\m3.png"); }
private static float GenerateMountains(float x, float y) { return((float)MountainNoise.GetNoise(x, y)); }