コード例 #1
0
ファイル: NoiseControl.cs プロジェクト: takaaptech/SharpNoise
        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;
        }
コード例 #2
0
ファイル: NoiseControl.cs プロジェクト: rthome/SharpNoise
        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;
        }
コード例 #3
0
        private static Bitmap CreateBitmap(Size size, NoiseMap map, NoiseConfig cfg)
        {
            var image    = new SharpNoise.Utilities.Imaging.Image(size.Width, size.Height);
            var renderer = new ImageRenderer
            {
                SourceNoiseMap   = map,
                DestinationImage = image
            };

            if (cfg.OutputGrayscale)
            {
                BuildGrayscaleRenderer(renderer);
            }
            else
            {
                BuildTerrainRenderer(renderer);
            }

            renderer.Render();

            return(image.ToGdiBitmap());
        }
コード例 #4
0
ファイル: Noise.cs プロジェクト: Czompi/Obsidian
        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);
        }
コード例 #5
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);
        }
コード例 #6
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;
        }
コード例 #7
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");
        }