示例#1
0
        public static void Main(String[] args)
        {
            Console.WriteLine("Procedurality CLI - (c)2009 Rob \"N3X15\" Nelson");
            Console.WriteLine("_______________________________________________________________\n");

            foreach (String s in args)
            {
                //Console.WriteLine(s);
            }
            Arguments CommandLine = new Arguments(args);

            String action = "help";
            String file   = "in.png";
            String ofile  = "out";
            int    seed   = DateTime.Now.Millisecond;

            Size = 256;
            bool FlipV = false;

            if (CommandLine["flip-v"] != null)
            {
                FlipV = true;
            }

            // --help
            if (CommandLine["help"] != null)
            {
                Help();
            }

            // --seed=1234567890
            if (CommandLine["seed"] != null)
            {
                seed = int.Parse(CommandLine["seed"]);
            }

            Console.WriteLine(" * Random seed: " + seed.ToString());

            if (CommandLine["size"] != null)
            {
                Size = uint.Parse(CommandLine["size"]);
            }

            Channel terrain;

            if (CommandLine["perlin"] != null)
            {
                Console.Write("Generating terrain with perlin noise...");
                terrain = new Mountain((int)Size, Utils.powerOf2Log2((int)Size) - 6, 0.5f, seed).toChannel();
                Console.WriteLine(" DONE!");
            }
            else if (CommandLine["in"] != null)
            {
                Console.Write("Loading " + file + "...");
                terrain = LoadTerrain(CommandLine["in"]);
                if (FlipV)
                {
                    terrain = terrain.flipV();
                }
                Console.WriteLine(" Done!");

                if (CommandLine["tiledir"] != null && CommandLine["tilesize"] != null)
                {
                    string tiledir = CommandLine["tiledir"];
                    if (!Directory.Exists(tiledir))
                    {
                        Directory.CreateDirectory(tiledir);
                    }
                    MakeTiles(terrain, uint.Parse(CommandLine["tilesize"]), tiledir);
                }
            }
            else if (CommandLine["hills"] != null)
            {
                Console.Write("Generating " + CommandLine["hills"] + " hills...");
                terrain = HillsAlgo((int)Size, int.Parse(CommandLine["hills"]), seed);
                Console.WriteLine(" DONE!");
            }
            else if (CommandLine["craters"] != null)
            {
                Console.Write("Generating " + CommandLine["craters"] + " craters...");
                terrain = CratersAlgo((int)Size, int.Parse(CommandLine["craters"]), seed);
                Console.WriteLine(" DONE!");
            }
            else
            {
                Console.WriteLine("Please use --perlin, --in, --hills, or --craters to load some terrain.");
                return;
            }

            ofile = args[args.Length - 1];


            if (CommandLine["addcliffs"] != null)
            {
                int features = 4;
                if (CommandLine["features"] != null)
                {
                    features = int.Parse(CommandLine["features"]);
                }

                Console.WriteLine("Adding cliffs.");
                // add mountain peaks
                Voronoi voronoi = new Voronoi(256, 4, 4, 1, 1f, seed);
                Channel cliffs  = voronoi.getDistance(-1f, 1f, 0f).brightness(1.5f).multiply(0.33f);
                terrain.multiply(0.67f).channelAdd(cliffs);
                terrain.channelSubtract(voronoi.getDistance(1f, 0f, 0f).gamma(.5f).flipV().rotate(90));
            }
            if (CommandLine["iceage"] != null)
            {
                float hills = 0.5f;
                if (CommandLine["hillratio"] != null)
                {
                    hills = float.Parse(CommandLine["hillratio"]);
                }

                Console.WriteLine("Ice age erosion in progress.");
                terrain.perturb(new Midpoint((int)Size, 2, hills, seed).toChannel(), 0.25f);
            }

            if (CommandLine["thermal"] != null)
            {
                float hills = 0.5f;
                if (CommandLine["hillratio"] != null)
                {
                    hills = float.Parse(CommandLine["hillratio"]);
                }

                terrain.erodeThermal((24f - hills * 12f) / (int)Size, (int)Size >> 2);
            }

            // Hydraulic Erosion
            if (CommandLine["hydraulic"] != null)
            {
                Console.WriteLine("Hydraulic erosion in progress.");

                // let it rain for a couple of thousand years
                float hills = 0.5f;
                if (CommandLine["hillratio"] != null)
                {
                    hills = float.Parse(CommandLine["hillratio"]);
                }

                terrain.erode((24f - hills * 12f) / (int)Size, (int)Size >> 2);
            }
            if (CommandLine["slow-hydro"] != null)
            {
                terrain = ErosionHydraulic.erode1(terrain, terrain.copy().multiply(0.01f), 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode2(terrain, terrain.copy().multiply(0.01f), 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode3(terrain, terrain.copy().multiply(0.01f), 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode4(terrain, 0.01f, 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode5(terrain, terrain.copy().multiply(0.01f), 0.1f, 0.1f, 0.1f, 20f, 0.5f, 1, 100);
            }
            if (CommandLine["add-silt"] != null)
            {
                float wl = 20f / 256f;
                wl      = float.Parse(CommandLine["add-silt"]);
                terrain = terrain.silt(wl, true);
            }
            if (CommandLine["add-river"] != null)
            {
                terrain.normalize(1f, 0.3f);
                List <PathFinderNode> path;
                terrain = (new RiverBuilder(terrain)).GenerateRiver(20f, seed, out path).toChannel();
                terrain.normalize();
                string rpath = "";
                foreach (PathFinderNode p in path)
                {
                    rpath += string.Format("{0},{1}\n", p.X, p.Y);
                }
                File.WriteAllText(ofile + ".river.txt", rpath);
            }
            terrain.smooth(1);

            float nm = 0f;
            float nM = 1f;

            if (CommandLine["range-max"] != null)
            {
                nM = float.Parse(CommandLine["range-max"]);
            }

            if (CommandLine["range-min"] != null)
            {
                nm = float.Parse(CommandLine["range-min"]);
            }

            if (nm > 1f || nM > 1f)
            {
                nm = nm / 256f;
                nM = nM / 256f;
            }

            terrain.normalize(nm, nM).toLayer().saveAsPNG(ofile);
        }
示例#2
0
        public static void Main(String[] args)
        {
            Console.WriteLine("Procedurality CLI - (c)2009-2013 Rob \"N3X15\" Nelson");
            Console.WriteLine("_______________________________________________________________\n");
            Console.WriteLine("For full licensing information, please see COPYING.");

            Arguments CommandLine = new Arguments(args);

            String file = "in.png";
            String ofile = "out";
            long seed = DateTime.Now.Millisecond;
            Size size = new Size();
            size.Height = 256;
            size.Width = 256;
            bool FlipV = false;
            if (CommandLine["flip-v"] != null)
                FlipV = true;

            // --help
            if (CommandLine["help"] != null)
                Help();

            // --seed=1234567890
            if (CommandLine["seed"] != null)
                seed = long.Parse(CommandLine["seed"]);

            Console.WriteLine(" * Random seed: " + seed.ToString());

            if (CommandLine["size"] != null)
            {
                // --size=256x256
                string[] sc = CommandLine["size"].Split('x');
                if (sc.Length == 1)
                {
                    size.Height = size.Width = uint.Parse(sc[0]);
                }
                else if (sc.Length == 2)
                {
                    size.Height = uint.Parse(sc[0]);
                    size.Width = uint.Parse(sc[1]);
                }
            }

            Channel terrain;
            if (CommandLine["perlin"] != null)
            {
                Console.Write("Generating terrain with perlin noise...");
                terrain = new Mountain((int)size.Height, (int)size.Width, Utils.powerOf2Log2((int)size.Width) - 6, 0.5f, seed).toChannel();
                Console.WriteLine(" DONE!");
            }
            else if (CommandLine["in"] != null)
            {
                Console.Write("Loading " + file + "...");
                terrain = LoadTerrain(CommandLine["in"]);
                if (FlipV) terrain = terrain.flipV();
                Console.WriteLine(" Done!");

                if (CommandLine["tiledir"] != null && CommandLine["tilesize"] != null)
                {
                    string tiledir = CommandLine["tiledir"];
                    if (!Directory.Exists(tiledir))
                        Directory.CreateDirectory(tiledir);
                    MakeTiles(terrain, uint.Parse(CommandLine["tilesize"]), tiledir);
                }
            }
            else if (CommandLine["hills"] != null)
            {
                Console.Write("Generating " + CommandLine["hills"] + " hills...");
                terrain = HillsAlgo((int)size.Height, (int)size.Width, int.Parse(CommandLine["hills"]), (int)seed);
                Console.WriteLine(" DONE!");
            }
            else if (CommandLine["craters"] != null)
            {
                Console.Write("Generating " + CommandLine["craters"] + " craters...");
                terrain = CratersAlgo((int)size.Height, (int)size.Width, int.Parse(CommandLine["craters"]), (int)seed);
                Console.WriteLine(" DONE!");
            }
            else
            {
                Console.WriteLine("Please use --perlin, --in, --hills, or --craters to load some terrain.");
                return;
            }

            ofile = args[args.Length - 1];

            if (CommandLine["addcliffs"] != null)
            {
                int features = 4;
                if (CommandLine["features"] != null)
                    features = int.Parse(CommandLine["features"]);

                Console.WriteLine("Adding cliffs.");
                // add mountain peaks
                Voronoi voronoi = new Voronoi((int)size.Height, (int)size.Width, 4, 4, 1, 1f, seed);
                Channel cliffs = voronoi.getDistance(-1f, 1f, 0f).brightness(1.5f).multiply(0.33f);
                terrain.multiply(0.67f).channelAdd(cliffs);
                terrain.channelSubtract(voronoi.getDistance(1f, 0f, 0f).gamma(.5f).flipV().rotate(90));
            }
            if (CommandLine["iceage"] != null)
            {
                float hills = 0.5f;
                if (CommandLine["hillratio"] != null)
                    hills = float.Parse(CommandLine["hillratio"]);

                Console.WriteLine("Ice age erosion in progress.");
                terrain.perturb(new Midpoint((int)size.Height, (int)size.Width, 2, hills, seed).toChannel(), 0.25f);
            }

            if (CommandLine["thermal"] != null)
            {
                float hills = 0.5f;
                if (CommandLine["hillratio"] != null)
                    hills = float.Parse(CommandLine["hillratio"]);

                terrain.erodeThermal((24f - hills * 12f) / (int)size.Height, (int)size.Height >> 2);
            }

            // Hydraulic Erosion
            if (CommandLine["hydraulic"] != null)
            {
                Console.WriteLine("Hydraulic erosion in progress.");

                // let it rain for a couple of thousand years
                float hills = 0.5f;
                if (CommandLine["hillratio"] != null)
                    hills = float.Parse(CommandLine["hillratio"]);

                terrain.erode((24f - hills * 12f) / (int)size.Height, (int)size.Height >> 2);
            }
            if (CommandLine["slow-hydro"] != null)
            {
                terrain = ErosionHydraulic.erode1(terrain, terrain.copy().multiply(0.01f), 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode2(terrain, terrain.copy().multiply(0.01f), 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode3(terrain, terrain.copy().multiply(0.01f), 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode4(terrain, 0.01f, 0.1f, 1, 100);
                terrain = ErosionHydraulic.erode5(terrain, terrain.copy().multiply(0.01f), 0.1f, 0.1f, 0.1f, 20f, 0.5f, 1, 100);
            }
            if (CommandLine["add-silt"] != null)
            {
                float wl = 20f / 256f;
                wl = float.Parse(CommandLine["add-silt"]);
                terrain = terrain.silt(wl, true);
            }
            /*
            if(CommandLine["add-river"]!=null)
            {
                terrain.normalize(1f,0.3f);
                List<PathFinderNode> path;
                terrain=(new RiverBuilder(terrain)).GenerateRiver(20f,seed,out path).toChannel();
                terrain.normalize();
                string rpath="";
                foreach(PathFinderNode p in path)
                {
                    rpath+=string.Format("{0},{1}\n",p.X,p.Y);
                }
                File.WriteAllText(ofile+".river.txt",rpath);
            }
            */
            terrain.smooth(1);

            float nm = 0f;
            float nM = 1f;
            if (CommandLine["range-max"] != null)
                nM = float.Parse(CommandLine["range-max"]);

            if (CommandLine["range-min"] != null)
                nm = float.Parse(CommandLine["range-min"]);

            if (nm > 1f || nM > 1f)
            {
                nm = nm / 256f;
                nM = nM / 256f;
            }

            terrain.normalize(nm, nM).toLayer().saveAsPNG(ofile);
        }