Example #1
0
        public World()
        {
            _seed   = new Random().Next();
            _random = new Random(_seed);

            _perlin = new Perlin
            {
                Seed        = _seed,
                OctaveCount = OctaveCount,
                Frequency   = Frequency,
                //Persistence = Persistence
            };

            _scaleBias = new ScaleBias
            {
                Source0 = _perlin,
                Scale   = Scale,
                Bias    = Bias
            };

            _clamp = new Clamp
            {
                LowerBound = LowerBound,
                UpperBound = UpperBound,
                Source0    = _scaleBias
            };

            _builder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap   = new NoiseMap(),
                SourceModule   = _clamp,
                EnableSeamless = false
            };
            _builder.SetDestSize(Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE);
        }
Example #2
0
    public async void TransitionsAsync()
    {
        OverworldGenerator og       = new OverworldGenerator();
        OverworldTerrain   noiseGen = new OverworldTerrain(true);
        await Task.Run(() =>
        {
            var map = new NoiseMap();
            PlaneNoiseMapBuilder builder =
                new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map, SourceModule = noiseGen.transitions
            };

            var image = new Image();
            var transitionsRenderer = new ImageRenderer()
            {
                SourceNoiseMap = map, DestinationImage = image
            };
            transitionsRenderer.BuildGrayscaleGradient();
            builder.SetBounds(-400, 400, -300, 300);
            builder.SetDestSize(800, 600);
            builder.Build();
            transitionsRenderer.Render();

            var bmp = transitionsRenderer.DestinationImage.ToGdiBitmap();
            bmp.Save("_transitions.bmp");

            Assert.Equal(0, 0);
        });
    }
        public TerrainGenerator()
        {
            // The noise source - a simple Perlin noise generator will do for this sample
            var noiseSource = new Perlin
            {
                Seed = new Random().Next()
            };


            // Create a new, empty, noise map and initialize a new planar noise map builder with it
            var noiseMap        = new NoiseMap();
            var noiseMapBuilder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap = noiseMap,
                SourceModule = noiseSource
            };

            // Set the size of the noise map
            noiseMapBuilder.SetDestSize(100, 100);

            // Set the bounds of the noise mpa builder
            // These are the coordinates in the noise source from which noise values will be sampled
            noiseMapBuilder.SetBounds(-3, 3, -2, 2);

            // Build the noise map - samples values from the noise module above,
            // using the bounds coordinates we have passed in the builder
            noiseMapBuilder.Build();
        }
Example #4
0
        void SetupNoiseMapBuilder()
        {
            // Set up noise module tree
            // TranslatePoint is used to shift the generated noise over time
            TimeTranslator = new TranslatePoint
            {
                // Scales the generated noise values down to 80%
                Source0 = new ScaleBias
                {
                    Scale = 0.8,
                    Bias  = 0,
                    // Scale coordinates down to get some rougher structures
                    Source0 = new ScalePoint
                    {
                        // Scale down xz-plane
                        XScale = 0.0375,
                        ZScale = 0.0375,
                        // Scale down "time"
                        YScale  = 0.625,
                        Source0 = new Billow(),
                    },
                },
            };

            // Set up target noise map and noise map builder
            NoiseMap        = new NoiseMap();
            NoiseMapBuilder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap = NoiseMap,
                SourceModule = TimeTranslator,
            };
            NoiseMapBuilder.SetBounds(0, LongitudeBands, 0, LatitudeBands);
            NoiseMapBuilder.SetDestSize(LongitudeBands, LatitudeBands);
        }
Example #5
0
        public NoiseControl()
        {
            InitializeComponent();

            var map     = new NoiseMap();
            var builder = new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map,
            };

            builder.SetDestSize(pictureBox.Width, pictureBox.Height);
            m_noiseBuilder = builder;

            var image    = new SharpNoise.Utilities.Imaging.Image();
            var renderer = new ImageRenderer()
            {
                SourceNoiseMap   = map,
                DestinationImage = image,
            };

            if (greyRadioButton.Checked)
            {
                renderer.BuildGrayscaleGradient();
            }
            else if (terrainRadioButton.Checked)
            {
                renderer.BuildTerrainGradient();
            }
            else
            {
                throw new Exception();
            }

            m_imageRenderer = renderer;
        }
    public static NoiseMap GetMap(NoisePackage package)
    {
        Perlin noiseSource = new Perlin
        {
            Seed        = package.Seed,
            OctaveCount = package.OctaveCount,
            Persistence = package.Persistence,
            Quality     = (NoiseQuality)package.Quality,
            Frequency   = package.Frequency
        };

        // Create a new, empty, noise map and initialize a new planar noise map builder with it
        var noiseMap        = new NoiseMap();
        var noiseMapBuilder = new PlaneNoiseMapBuilder
        {
            DestNoiseMap = noiseMap,
            SourceModule = noiseSource
        };

        // Set the size of the noise map
        noiseMapBuilder.SetDestSize(Program.MapWidth, Program.MapHeight);

        // Set the bounds of the noise mpa builder
        // These are the coordinates in the noise source from which noise values will be sampled
        noiseMapBuilder.SetBounds(-3, 3, -2, 2);

        // Build the noise map - samples values from the noise module above,
        // using the bounds coordinates we have passed in the builder
        noiseMapBuilder.Build();

        return(noiseMap);
    }
Example #7
0
        /// <summary>
        /// Generate the noise values
        /// </summary>
        private void GenerateNoise()
        {
            var module = new Perlin()
            {
                Seed        = this.Seed + 333211,
                Frequency   = 20.0,
                OctaveCount = 2
            };

            var bounds   = new System.Drawing.RectangleF(4, 1, 1, 1);
            var noiseMap = new NoiseMap();
            var builder  = new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = noiseMap,
                SourceModule = module
            };

            builder.SetDestSize(this.Dimensions.Width, this.Dimensions.Height);

            builder.SetBounds(bounds.Left, bounds.Right, bounds.Top, bounds.Bottom);
            builder.Build();

            for (var ix = 0; ix < this.Dimensions.Width; ++ix)
            {
                for (var iy = 0; iy < this.Dimensions.Height; ++iy)
                {
                    this.NoiseValues[ix, iy] = noiseMap[ix, iy];
                }
            }

            this.Normalize(this.NoiseValues);
        }
Example #8
0
        private void GeneratePatch(int abundance, int tileNum)
        {
            NoiseMap output = new NoiseMap();
            Perlin   per    = new Perlin()
            {
                Seed = seed.GetHashCode(), Frequency = 1, OctaveCount = Perlin.DefaultOctaveCount, Lacunarity = Perlin.DefaultLacunarity, Persistence = Perlin.DefaultPersistence, Quality = NoiseQuality.Best
            };
            var noiseMapBuilder = new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = output, SourceModule = per
            };

            noiseMapBuilder.SetDestSize(width, height);
            noiseMapBuilder.SetBounds(-2, 3, -2, 3);
            noiseMapBuilder.Build();

            for (int r = 0; r < width; r++)
            {
                for (int c = 0; c < height; c++)
                {
                    if (map[r, c] != 0)
                    {
                        map[r, c] = (Math.Abs(output[r, c]) * 100) > 80 ? 2 : map[r, c];
                    }
                }
            }
        }
Example #9
0
 public void Build()
 {
     if ((noiseMap == null) || noiseMap.IsEmpty)
     {
         noiseMapBuilder.SetDestSize(Width, Height);
         noiseMapBuilder.SetBounds(Width / 10, Width, Height / 10, Height);
         noiseMapBuilder.Build();
     }
 }
Example #10
0
        public static void Main(string[] args)
        {
            // The noise source - a simple Perlin noise generator will do for this sample
            var noiseSource = new Perlin
            {
                Seed = new Random().Next()
            };

            // Create a new, empty, noise map and initialize a new planar noise map builder with it
            var noiseMap        = new NoiseMap();
            var noiseMapBuilder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap = noiseMap,
                SourceModule = noiseSource
            };

            // Set the size of the noise map
            noiseMapBuilder.SetDestSize(1280, 720);

            // Set the bounds of the noise mpa builder
            // These are the coordinates in the noise source from which noise values will be sampled
            noiseMapBuilder.SetBounds(-3, 3, -2, 2);

            // Build the noise map - samples values from the noise module above,
            // using the bounds coordinates we have passed in the builder
            noiseMapBuilder.Build();

            // Create a new image and image renderer
            var image    = new Image();
            var renderer = new ImageRenderer
            {
                SourceNoiseMap   = noiseMap,
                DestinationImage = image
            };

            // The renderer needs to know how to map noise values to colors.
            // In this case, we use one of the predefined gradients, specifically the terrain gradient,
            // which maps lower noise values to blues and greens and higher values to brouns and whites.
            // This simulates the look of a map with water, grass and vegetation, dirt and mountains.
            renderer.BuildTerrainGradient();

            // Before rendering the image, we could set various parameters on the renderer,
            // such as the position and color of the light source.
            // But we aren't going to bother for this sample.

            // Finally, render the image
            renderer.Render();

            // Finally, save the rendered image as a PNG in the current directory
            using (var fs = File.OpenWrite("NoiseMap.png"))
            {
                image.SaveGdiBitmap(fs, ImageFormat.Png);
            }
        }
Example #11
0
        public virtual IMap2D <T> Generate(int width, int height)
        {
            var map = new NoiseMap(width, height);

            var builder = new PlaneNoiseMapBuilder();

            builder.EnableSeamless = true;
            builder.DestNoiseMap   = map;
            builder.SetBounds(-5, 5, -5, 5);
            builder.SetDestSize(width, height);
            builder.SourceModule = Module;
            builder.Build();

            return(TransformMap(map));
        }
Example #12
0
        public void PlanarRenderTest()
        {
            var plane = new PlaneNoiseMapBuilder();

            plane.SetBounds(-1, 1, -1, 1);
            plane.SetDestSize(256, 256);
            plane.SourceModule   = module;
            plane.DestNoiseMap   = noiseMap;
            plane.EnableSeamless = false;
            plane.Build();

            renderer.SourceNoiseMap   = noiseMap;
            renderer.DestinationImage = textureImage;
            renderer.Render();
        }
Example #13
0
        public static NoiseMap Generate(int width, int height)
        {
            var noiseMapBuilder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap = noiseMap,
                SourceModule = turbulence
            };

            voronoi.Seed = Seed;
            voronoi.Type = Cell.CellType.Minkowsky;
            noiseMapBuilder.SetDestSize(width, height);
            noiseMapBuilder.SetBounds(-5, 5, 0, 10);
            noiseMapBuilder.Build();
            return(noiseMap);
        }
Example #14
0
        public static NoiseMap getNoiseMap(double seedx, double seedy, int height, int width, double lacunarity, double persistence)
        {
            NoiseMap             map     = new NoiseMap();
            PlaneNoiseMapBuilder builder = new PlaneNoiseMapBuilder();
            Simplex simplex = new Simplex();

            simplex.Lacunarity   = lacunarity;
            simplex.Persistence  = persistence;
            builder.SourceModule = simplex;
            builder.DestNoiseMap = map;
            builder.SetDestSize(800, 600);
            builder.SetBounds(seedx, seedx + width, seedy, seedy + height);
            builder.Build();
            return(map);
        }
Example #15
0
        public void WoodTexture_PlanarRender()
        {
            var noiseMap = new NoiseMap();
            var plane    = new PlaneNoiseMapBuilder();

            plane.SetBounds(-1, 1, -1, 1);
            plane.SetDestSize(256, 256);
            plane.SourceModule   = testModule;
            plane.DestNoiseMap   = noiseMap;
            plane.EnableSeamless = false;
            plane.Build();

            testRenderer.SourceNoiseMap   = noiseMap;
            testRenderer.DestinationImage = testTextureImage;
            testRenderer.Render();
        }
Example #16
0
        /// <summary>
        /// Generate the height map
        /// </summary>
        private void Generate()
        {
            //var bounds = new System.Drawing.RectangleF(6, 1, 3, 3);
            //var bounds = new System.Drawing.RectangleF(6, 1, 4, 4);
            var bounds      = new System.Drawing.RectangleF(6, 1, 5, 5);
            var noiseModule = this.BuildModuleTree();
            var noiseMap    = new NoiseMap();
            var builder     = new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = noiseMap,
                SourceModule = noiseModule
            };

            builder.SetDestSize(this.Dimensions.Width, this.Dimensions.Height);

            builder.SetBounds(bounds.Left, bounds.Right, bounds.Top, bounds.Bottom);
            builder.Build();

            for (var ix = 0; ix < this.Dimensions.Width; ++ix)
            {
                for (var iy = 0; iy < this.Dimensions.Height; ++iy)
                {
                    this.Values[ix, iy] = noiseMap[ix, iy];
                }
            }

            this.Normalize();

            if (this.Parameters.ForceOceanSides)
            {
                this.MaskSides();
            }

            if (this.Parameters.AccentuateHills)
            {
                this.AccentuatePeaks();
                this.Normalize();
            }

            this.FillSinks();

            this.DetermineHeightLevels();
        }
Example #17
0
        public async void SameAsync()
        {
            OverworldTerrainSettings generatorSettings = new OverworldTerrainSettings();

            generatorSettings.Seed = 137;
            OverworldTerrain noiseGen = new OverworldTerrain(generatorSettings, true);

            var map = new NoiseMap();

            PlaneNoiseMapBuilder builder = new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map,
                SourceModule = noiseGen.Result
            };

            var image    = new SharpNoise.Utilities.Imaging.Image();
            var renderer = new ImageRenderer()
            {
                SourceNoiseMap   = map,
                DestinationImage = image
            };

            //renderer.BuildGrayscaleGradient();
            renderer.BuildTerrainGradient();

            builder.SetBounds(-2024, 2024, -2024, 2024);
            builder.SetDestSize(1024, 1024);
            builder.Build();

            renderer.Render();

            var bmp = renderer.DestinationImage.ToGdiBitmap();

            bmp.Save("terrain.bmp");

            Assert.Equal(0, 0);
        }
Example #18
0
    public async void TerrainBlendAsync()
    {
        OverworldGenerator og       = new OverworldGenerator();
        OverworldTerrain   noiseGen = new OverworldTerrain(true);
        await Task.Run(() =>
        {
            var noise = new SharpNoise.Modules.ScaleBias()
            {
                Scale   = 4,
                Source0 = noiseGen.selectiveBlend
            };

            var map = new NoiseMap();
            PlaneNoiseMapBuilder builder =
                new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map, SourceModule = noise
            };

            var image = new Image();
            var transitionsRenderer = new ImageRenderer()
            {
                SourceNoiseMap = map, DestinationImage = image
            };
            transitionsRenderer.BuildTerrainGradient();
            builder.SetBounds(-400, 400, -300, 300);
            builder.SetDestSize(800, 600);
            builder.Build();
            transitionsRenderer.Render();

            var bmp = transitionsRenderer.DestinationImage.ToGdiBitmap();
            bmp.Save("_blendedterrain.bmp");

            Assert.Equal(0, 0);
        });
    }
Example #19
0
        protected virtual NoiseMap BuildNoiseMap(Size size, NoiseConfig cfg)
        {
            var noiseSource = BuildNoiseSource(cfg);

            var noiseMap = new NoiseMap(size.Width, size.Height);

            var noiseMapBuilder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap   = noiseMap,
                SourceModule   = noiseSource,
                EnableSeamless = false
            };

            noiseMapBuilder.SetDestSize(noiseMap.Width, noiseMap.Height);
            noiseMapBuilder.SetBounds(0, noiseMap.Width * 0.01, 0, noiseMap.Height * 0.01);
            noiseMapBuilder.Build();
            PostProcessing(size, cfg, noiseMap);
            Size2 = size.Width * size.Height;
            Total = noiseMap.Data.Sum();

            Density  = Total / Size2;
            Coverage = noiseMap.Data.Count(v => v > 0f) / Size2;
            return(noiseMap);
        }
Example #20
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            nbEnemy = 0;

            gameover = false;

            world = new World(new Vector2(0, 0));

            debugView = new DebugView();
            debugView.LoadContent(GraphicsDevice, Content);

            inputHelper            = new InputHelper(resolutionIndependence);
            inputHelper.ShowCursor = true;

            shadowsRendering = new ShadowsRenderer();

            listGraphicObj = new List <GraphicObj>();

            inputHelper.LoadContent();

            font = Content.Load <SpriteFont>("pixelSpriteFont");

            Texture2D textureCarre  = Content.Load <Texture2D>("carre");
            Texture2D textureCarre2 = Content.Load <Texture2D>("carre2");
            Texture2D textureTotem  = Content.Load <Texture2D>("Totem");

            bouleRouge    = Content.Load <Texture2D>("blood");
            blood1        = Content.Load <Texture2D>("blood1");
            blood2        = Content.Load <Texture2D>("blood2");
            blood3        = Content.Load <Texture2D>("blood3");
            debugNodeBusy = Content.Load <Texture2D>("debugPathFinderNode");
            debugNodeFree = Content.Load <Texture2D>("debugPathFinderNode2");

            particuleSystem = new ParticuleSystem();

            //pathFinder = new PathFinder(2);
            pFinder = new PathFinder();
            pFinder.BuildtNavMeshes(6, 10);

            mapFactory = new MapFactory();
            mapFactory.newMap(listGraphicObj, seedIndexToLoad);
            seedIndexToLoad = -1;
            savedSeeds      = mapFactory.mGen.savedSeeds;
            var treeplanter = new TreePlanter(
                mapFactory.minX * pixelToMeter,
                mapFactory.maxX * pixelToMeter,
                mapFactory.minY * pixelToMeter,
                mapFactory.maxY * pixelToMeter,
                mapFactory.mGen.rand
                );

            frameRateCounter = new FrameRateCounter(font);

            particuleSystem.addParticuleSpawner(new SnowSpawner(new Vector2(100, 100), 0, player, new Vector2(475, -475)));

            snowMarkSpawner = new SnowMarkSpawner(new Vector2(0, 0), 0, player, new Vector2(0, 0));

            var noiseSource = new Perlin
            {
                Seed = mapFactory.mGen.rand.Next()
            };
            var noiseMap        = new NoiseMap();
            var noiseMapBuilder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap   = noiseMap,
                SourceModule   = noiseSource,
                EnableSeamless = true
            };

            //noiseMapBuilder.SetDestSize(300, 300);
            //noiseMapBuilder.SetBounds(-4.5, 4.5, -4.5, 4.5);
            noiseMapBuilder.SetDestSize(256, 256);
            noiseMapBuilder.SetBounds(2, 6, 1, 5);

            noiseMapBuilder.Build();

            textureImageNoise = new SharpNoise.Utilities.Imaging.Image();

            imageRendererNoise = new ImageRenderer
            {
                SourceNoiseMap   = noiseMap,
                DestinationImage = textureImageNoise,
                EnableLight      = true,
                LightContrast    = 1.0,
                LightBrightness  = 2.3,
                EnableWrap       = true
            };

            imageRendererNoise.ClearGradient();

            imageRendererNoise.AddGradientPoint(0.0000, new SharpNoise.Utilities.Imaging.Color(170, 180, 240, 255));
            imageRendererNoise.AddGradientPoint(1.000, new SharpNoise.Utilities.Imaging.Color(170, 180, 240, 255));

            imageRendererNoise.Render();

            renderedmap = createTexture(imageRendererNoise);

            minNoiseX = (int)mapFactory.minX - textureImageNoise.Width * 2;
            maxNoiseX = (int)mapFactory.maxX + textureImageNoise.Width * 2;
            minNoiseY = (int)mapFactory.minY - textureImageNoise.Height * 2;
            maxNoiseY = (int)mapFactory.maxY + textureImageNoise.Height * 2;

            menu = new Menu(font);
        }
    public static NoisePackage Generate()
    {
        // Randomly generate a package to return at the end of the method
        NoisePackage package = new NoisePackage
        {
            Seed        = new Random().Next(),
            OctaveCount = new Random().Next(3, 9),
            Persistence = new Random().NextDouble(),
            Quality     = (byte)NoiseQuality.Best,
            Frequency   = (double)new Random().Next(1, 3)
        };

        // The noise source - a simple Perlin noise generator will do for this sample
        Perlin noiseSource = new Perlin
        {
            Seed        = package.Seed,
            OctaveCount = package.OctaveCount,
            Persistence = package.Persistence,
            Quality     = (NoiseQuality)package.Quality,
            Frequency   = package.Frequency
        };

        // Create a new, empty, noise map and initialize a new planar noise map builder with it
        var noiseMap        = new NoiseMap();
        var noiseMapBuilder = new PlaneNoiseMapBuilder
        {
            DestNoiseMap = noiseMap,
            SourceModule = noiseSource
        };

        // Set the size of the noise map
        noiseMapBuilder.SetDestSize(Program.MapWidth, Program.MapHeight);

        // Set the bounds of the noise mpa builder
        // These are the coordinates in the noise source from which noise values will be sampled
        noiseMapBuilder.SetBounds(-3, 3, -2, 2);

        // Build the noise map - samples values from the noise module above,
        // using the bounds coordinates we have passed in the builder
        noiseMapBuilder.Build();

        // Create a new image and image renderer
        var image    = new Image();
        var renderer = new ImageRenderer
        {
            SourceNoiseMap   = noiseMap,
            DestinationImage = image
        };

        // The renderer needs to know how to map noise values to colors.
        // In this case, we use one of the predefined gradients, specifically the terrain gradient,
        // which maps lower noise values to blues and greens and higher values to brouns and whites.
        // This simulates the look of a map with water, grass and vegetation, dirt and mountains.
        renderer.BuildGrayscaleGradient();

        // Before rendering the image, we could set various parameters on the renderer,
        // such as the position and color of the light source.
        // But we aren't going to bother for this sample.

        // Finally, render the image
        renderer.Render();

        // Finally, save the rendered image as a PNG in the current directory
        using (var fs = File.OpenWrite("NoiseMapGrayscale.png"))
        {
            image.SaveGdiBitmap(fs, ImageFormat.Png);
        }

        renderer.BuildTerrainGradient();

        renderer.Render();

        using (var fs = File.OpenWrite("NoiseMapColor.png"))
        {
            image.SaveGdiBitmap(fs, ImageFormat.Png);
        }

        Process photoViewer = new Process();

        photoViewer.StartInfo.FileName = "NoiseMapColor.png";
        photoViewer.Start();

        Console.WriteLine(
            "\n      Frequency: " + noiseSource.Frequency +
            "\n      Lacunarity: " + noiseSource.Lacunarity +
            "\n      Octaves: " + noiseSource.OctaveCount +
            "\n      Persistence: " + noiseSource.Persistence +
            "\n      Seed: " + noiseSource.Seed + "\n");

        return(package);
    }
Example #22
0
        async void GenerateMapAsync(int seed)
        {
            GeneratorBase generator = null;

            generator = new GeneratorBase();
            //generator = new PlanetBlendGenerator();
            //generator = new PlanetSelectGenerator();
            var module       = generator.GetModule(seed);
            var elevationMap = new NoiseMap();
            var builder      = new PlaneNoiseMapBuilder();

            //builder.EnableSeamless = true;
            //builder.EnableSeamless = false;
            builder.SetBounds(0, _width / _minSize, 0, _width / _minSize);
            builder.SetDestSize(_width, 1);
            builder.SourceModule = module;
            builder.DestNoiseMap = elevationMap;

            var  cts       = new CancellationTokenSource();
            bool cancelled = false;

            try
            {
                await builder.BuildAsync(cts.Token);
            }
            catch (System.OperationCanceledException)
            {
                cancelled = true;
            }

            // Find max/min
            var   map = builder.DestNoiseMap;
            float max = float.MinValue;
            float min = float.MaxValue;

            for (int x = 0; x < map.Width; x++)
            {
                for (int y = 0; y < map.Height; y++)
                {
                    var value = map[x, y];
                    if (value >= max)
                    {
                        max = value;
                    }
                    if (value <= min)
                    {
                        min = value;
                    }
                }
            }

            // Generate height map from 2 maps
            var delta     = max - min;
            var heightMap = new float[2 * map.Width];

            _width = map.Width;
            for (int x = 0; x < heightMap.Length; x++)
            {
                int index = x % map.Width;
                var value = map[index, 0];
                value        = (value - min) / delta;
                heightMap[x] = value;
            }

            // Dig launcpad
            var launchpadSize   = _baseSize / 2;
            var launchpadHeigth = 0f;
            var counter         = 0f;

            for (int x = heightMap.Length / 2 - launchpadSize; x < heightMap.Length / 2 + launchpadSize; x++)
            {
                launchpadHeigth += heightMap[x];
                counter         += 1f;
            }
            launchpadHeigth /= counter;
            for (int x = heightMap.Length / 2 - launchpadSize; x < heightMap.Length / 2 + launchpadSize; x++)
            {
                heightMap[x] = launchpadHeigth;
            }

            // generate level map
            _heightMap = new int[2 * _width];
            _levelMap  = new int[2 * _width, 2 * _height];
            int x0        = _levelMap.GetLength(0) / 2;
            int y0        = _levelMap.GetLength(1) / 2;
            int z0        = -1;
            int zeroLevel = y0 - Mathf.RoundToInt(_height * launchpadHeigth) - 1;

            for (int x = 0; x < _levelMap.GetLength(0); x++)
            {
                var value  = heightMap[x];
                var height = Mathf.RoundToInt(_height * value) + zeroLevel;
                if (height >= 2 * _height)
                {
                    height = 2 * _height - 1;
                }
                _heightMap[x] = height;

                for (int y = 0; y < height; y++)
                {
                    _levelMap[x, y] = 1;
                }
            }

            // place tiles
            _tilemap.ClearAllTiles();
            for (int x = 0; x < _levelMap.GetLength(0); x++)
            {
                for (int y = 0; y < _levelMap.GetLength(1); y++)
                {
                    Vector3Int pos = new Vector3Int(x - x0, y - y0, z0);
                    var        h   = _levelMap[x, y];
                    if (h > 0)
                    {
                        _tilemap.SetTile(pos, _tile);
                    }
                }
            }

            if (cancelled)
            {
                return;
            }
        }
Example #23
0
        private void GenerateNoiseMaps()
        {
            tbLogView.Text = "Started\r\n";
            int SizeX;
            int SizeY;

            try
            {
                SizeX = Int32.Parse(tbWidth.Text);
                SizeY = Int32.Parse(tbHeight.Text);

                NoiseBitmapTerrain = new Bitmap(SizeX, SizeY);
                NoiseBitmapHeight  = new Bitmap(SizeX, SizeY);
                tbLogView.AppendText("Size OK \r\n");
            }
            catch (Exception)
            {
                SizeX = 250;
                SizeY = 250;
                MessageBox.Show("Nonparsable size values! Running at 250x250\r\n");
                NoiseBitmapTerrain = new Bitmap(250, 250);
                NoiseBitmapTerrain = new Bitmap(250, 250);
                tbLogView.AppendText("Size was incorrect, going default\r\n");
            }
            tbLogView.AppendText("Loading Perlin from Noiser(legacy)\r\n");
            SharpNoise.Modules.Perlin perlin = new SharpNoise.Modules.Perlin();
            tbLogView.AppendText("Loading OK\r\n");
            try
            {
                perlin.OctaveCount = Int32.Parse(tbOctaves.Text);
                perlin.Seed        = Int32.Parse(tbSeed.Text);
                perlin.Frequency   = Double.Parse(tbFreq.Text);
                tbLogView.AppendText("Settings OK\r\n");
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong octaves count or seed! Running at 1 octave and seed 000000 @ Frequency = 10.");
                perlin.OctaveCount = 1;
                perlin.Seed        = 000000;
                perlin.Frequency   = 10.0;
                tbLogView.AppendText("Setting incorrect, going default\r\n");
            }
            double down, up, right, left;

            try
            {
                down  = Double.Parse(tbTileDown.Text);
                up    = Double.Parse(tbTileUp.Text);
                left  = Double.Parse(tbTileLeft.Text);
                right = Double.Parse(tbTileRight.Text);
                tbLogView.AppendText("Tiles OK\r\n");
            }
            catch (Exception)
            {
                up    = 3;
                left  = -3;
                right = 3;
                down  = -3;
                tbLogView.AppendText("Tiles incorrect, going default\r\n");
            }
            var NoiseMap = new NoiseMap(SizeX, SizeY);

            if (comboModuleSelector.SelectedIndex == 0)
            {
                var NoiseMapBuilder = new PlaneNoiseMapBuilder()
                {
                    DestNoiseMap = NoiseMap, SourceModule = perlin
                };
                tbLogView.AppendText("Module OK, Destination OK\r\n");
                NoiseMapBuilder.SetDestSize(SizeX, SizeY);

                NoiseMapBuilder.SetBounds(left, right, down, up);
                tbLogView.AppendText("Building maps.....\r\n");
                NoiseMapBuilder.Build();
            }
            if (comboModuleSelector.SelectedIndex == 1)
            {
                var GlobeMapBuilder = new SphereNoiseMapBuilder()
                {
                    DestNoiseMap = NoiseMap, SourceModule = perlin
                };
                tbLogView.AppendText("Module OK, Destination OK\r\n");
                GlobeMapBuilder.SetDestSize(SizeX, SizeY);
                GlobeMapBuilder.SetBounds(down, up, left, right);
                GlobeMapBuilder.Build();
                tbLogView.AppendText("Building maps.....\r\n");
            }
            tbLogView.AppendText("Building OK\r\n");

            var ImageTerrain    = new SharpNoise.Utilities.Imaging.Image();
            var RendererTerrain = new ImageRenderer()
            {
                SourceNoiseMap   = NoiseMap,
                DestinationImage = ImageTerrain
            };

            tbLogView.AppendText("Renderer starting\r\n");

            if (chboxLightMap.IsChecked == true)
            {
                RendererTerrain.EnableLight     = true;
                RendererTerrain.LightAzimuth    = Double.Parse(tbLightAzimuth.Text);
                RendererTerrain.LightBrightness = Double.Parse(tbLightBrightness.Text);
                RendererTerrain.LightContrast   = Double.Parse(tbLightContrast.Text);
                RendererTerrain.LightElevation  = Double.Parse(tbLightElevation.Text);
                RendererTerrain.LightIntensity  = Double.Parse(tbLightIntensity.Text);
            }
            Thread ColorBuilder = new Thread(() =>
            {
                RendererTerrain.BuildTerrainGradient();
                RendererTerrain.Render();

                NoiseBitmapTerrain = ImageTerrain.ToGdiBitmap();
                ImageNoiseHolder.Dispatcher.Invoke(new Action(() =>
                {
                    ImageNoiseHolder.Source = BitmapToImageSource(NoiseBitmapTerrain);
                    tbLogView.AppendText("Done! Noise map OK, renderer OK\r\n");
                }));
            });

            ColorBuilder.Start();

            var ImageTerrainHeight    = new SharpNoise.Utilities.Imaging.Image();
            var RendererTerrainHeight = new ImageRenderer()
            {
                SourceNoiseMap   = NoiseMap,
                DestinationImage = ImageTerrainHeight
            };


            Thread heightBuilder = new Thread(() =>
            {
                RendererTerrainHeight.BuildGrayscaleGradient();
                RendererTerrainHeight.Render();
                NoiseBitmapHeight = ImageTerrainHeight.ToGdiBitmap();

                ImageNoiseHeightHolder.Dispatcher.Invoke(new Action(() =>
                {
                    ImageNoiseHeightHolder.Source = BitmapToImageSource(NoiseBitmapHeight);
                    tbLogView.AppendText("Done! Noise map OK, renderer OK\r\n");
                }));
            });

            heightBuilder.Start();

            tbLogView.AppendText("Process status: OK\r\n");
        }
Example #24
0
        /*
         * m - height map of moisture texture
         * function biome(e, m) {
         * if (e < 0.1) return OCEAN;
         * if (e < 0.12) return BEACH;
         *
         * if (e > 0.8) {
         * if (m < 0.1) return SCORCHED;
         * if (m < 0.2) return BARE;
         * if (m < 0.5) return TUNDRA;
         * return SNOW;
         * }
         *
         * if (e > 0.6) {
         * if (m < 0.33) return TEMPERATE_DESERT;
         * if (m < 0.66) return SHRUBLAND;
         * return TAIGA;
         * }
         *
         * if (e > 0.3) {
         * if (m < 0.16) return TEMPERATE_DESERT;
         * if (m < 0.50) return GRASSLAND;
         * if (m < 0.83) return TEMPERATE_DECIDUOUS_FOREST;
         * return TEMPERATE_RAIN_FOREST;
         * }
         *
         * if (m < 0.16) return SUBTROPICAL_DESERT;
         * if (m < 0.33) return GRASSLAND;
         * if (m < 0.66) return TROPICAL_SEASONAL_FOREST;
         * return TROPICAL_RAIN_FOREST;
         * }
         */
        void Generating()
        {
            //var mountain = BuildHeightMap(
            //   new ImprovedPerlin(),
            //   new SumFractal() {
            //       Frequency = 2,
            //       Lacunarity = 1,
            //       OctaveCount = 6,
            //   }, 0.1f);


            var map = new NoiseMap();

            try {
                var rectangle = new Rectangle(0, 0, width, height);
                var tree      = CreateNoiseTree();
                var builder   = new PlaneNoiseMapBuilder()
                {
                    DestNoiseMap = map,
                };
                builder.SourceModule = tree;
                builder.SetDestSize(width, height);
                builder.SetBounds(6.0, 10.0, 1.0, 5.0);
                builder.EnableSeamless = false;

                builder.Build();

                var image    = new SharpNoise.Utilities.Imaging.Image();
                var renderer = new ImageRenderer()
                {
                    SourceNoiseMap   = map,
                    DestinationImage = image,
                };
                renderer.BuildTerrainGradient();

                renderer.Render();

                Texture = renderer.DestinationImage.ToGdiBitmap();
            } catch (Exception ex) {
                ex.ToString();
            } finally {
                ClearNoiseTree();
            }

            var resources = Path.Combine("../../../../D3DLab.Wpf.Engine.App/Resources/terrain/");

            // using (var bitmap = new System.Drawing.Bitmap(Path.Combine(resources, "mask_circular_256x256.png"))) {
            HeightMap = new Vector3[height * width];
            var index = HeightMap.Length - 1;

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    //MakeIsland(ref e, x, y, 200f);
                    //var index = height * y + x;

                    var e = map.GetValue(x, y);

                    ReScale(ref e);

                    Redistribution(ref e);

                    HeightMap[index] = new Vector3(x, e * terrainParams.Correction, y);

                    MaxHeight = Math.Max(HeightMap[index].Y, MaxHeight);
                    MinHeight = Math.Min(HeightMap[index].Y, MinHeight);

                    index--;
                }
            }
            //}
            IsGenerated = true;
        }
Example #25
0
    public async void BiomesAsync()
    {
        await Task.Run(() =>
        {
            var map     = new NoiseMap();
            var builder = new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map, SourceModule = noiseGen.FinalBiomes
            };
            var image          = new Image();
            var biomesRenderer = new ImageRenderer()
            {
                SourceNoiseMap = map, DestinationImage = image
            };

            biomesRenderer.AddGradientPoint((int)Biomes.TheVoid, new Color(0, 0, 0, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Plains, new Color(86, 125, 70, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SunflowerPlains, new Color(255, 196, 63, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SnowyPlains, new Color(200, 200, 255, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.IceSpikes, new Color(100, 100, 255, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Desert, new Color(128, 128, 0, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Swamp, new Color(0, 128, 0, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Forest, new Color(32, 255, 32, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.FlowerForest, new Color(96, 255, 0, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.BirchForest, new Color(182, 255, 182, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.DarkForest, new Color(0, 100, 0, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.OldGrowthBirchForest, new Color(150, 255, 150, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.OldGrowthPineTaiga, new Color(1, 121, 111, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.OldGrowthSpruceTaiga, new Color(105, 193, 126, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Taiga, new Color(118, 128, 120, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SnowyTaiga, new Color(218, 228, 220, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Savanna, new Color(209, 163, 110, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SavannaPlateau, new Color(224, 190, 146, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.WindsweptHills, new Color(11, 102, 35, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.WindsweptGravellyHills, new Color(128, 164, 128, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.WindsweptForest, new Color(11, 102, 35, 196));
            biomesRenderer.AddGradientPoint((int)Biomes.WindsweptSavanna, new Color(209, 163, 110, 196));
            biomesRenderer.AddGradientPoint((int)Biomes.Jungle, new Color(41, 171, 135, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SparseJungle, new Color(41, 171, 135, 196));
            biomesRenderer.AddGradientPoint((int)Biomes.BambooJungle, new Color(221, 202, 133, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Badlands, new Color(167, 161, 143, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.ErodedBadlands, new Color(167, 161, 143, 196));
            biomesRenderer.AddGradientPoint((int)Biomes.WoodedBadlands, new Color(167, 224, 143, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Meadow, new Color(48, 186, 143, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Grove, new Color(120, 127, 86, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SnowySlopes, new Color(144, 184, 212, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.FrozenPeaks, new Color(144, 184, 255, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.JaggedPeaks, new Color(128, 128, 128, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.StonyPeaks, new Color(128, 128, 128, 196));
            biomesRenderer.AddGradientPoint((int)Biomes.River, new Color(38, 102, 145, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.FrozenRiver, new Color(186, 218, 232, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.Beach, new Color(248, 220, 172, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.SnowyBeach, new Color(248, 220, 255, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.StonyShore, new Color(170, 170, 170, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.WarmOcean, new Color(60, 181, 177, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.LukewarmOcean, new Color(40, 181, 177, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.DeepLukewarmOcean, new Color(40, 181, 177, 128));
            biomesRenderer.AddGradientPoint((int)Biomes.Ocean, new Color(0, 105, 148, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.DeepOcean, new Color(0, 105, 148, 128));
            biomesRenderer.AddGradientPoint((int)Biomes.ColdOcean, new Color(107, 197, 198, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.DeepColdOcean, new Color(107, 197, 198, 128));
            biomesRenderer.AddGradientPoint((int)Biomes.FrozenOcean, new Color(163, 191, 203, 255));
            biomesRenderer.AddGradientPoint((int)Biomes.DeepFrozenOcean, new Color(163, 191, 203, 128));
            biomesRenderer.AddGradientPoint((int)Biomes.MushroomFields, new Color(119, 103, 84, 255));


            builder.SetBounds(-400, 400, -300, 300);
            builder.SetDestSize(800, 600);
            builder.Build();
            biomesRenderer.Render();

            var bmp = biomesRenderer.DestinationImage.ToGdiBitmap();
            bmp.Save("_biomes.bmp");

            Assert.Equal(0, 0);
        });
    }