Esempio n. 1
0
        public List <PopulationCentre> buildData(out int[,] terrainMap)
        {
            var options      = new FractalOptions(10, 15);
            int n            = 10;
            var popMap       = WrappingFractal.fractal(128, n, n, options, FractalWrapMode.NoWrap, 89761234);
            var forestMap    = WrappingFractal.fractal(128, n, n, options, FractalWrapMode.NoWrap, 1245612);;
            var forestLevels = FractalUtility.getCutOffLevels(forestMap, new float[] { 80, 20 });
            var image        = new Bitmap(128 * n, 128 * n);

            terrainMap = new int[128 * n, 128 * n];
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    popMap[i, j] = popMap[i, j] - forestMap[i, j];
                }
            }
            var popLevels = FractalUtility.getCutOffLevels(popMap, new float[] { 98, 2 });

            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    popMap[i, j] = popMap[i, j] - popLevels[0];
                    if (popMap[i, j] < 0)
                    {
                        popMap[i, j] = 0;
                    }
                    var pop = (popMap[i, j] / (popLevels[1] - popLevels[0]));
                    if (forestMap[i, j] > forestLevels[0])
                    {
                        terrainMap[i, j] = 1;
                        forestMap[i, j] -= forestLevels[0];
                        pop -= 1f;
                        var g = (int)(255 * forestMap[i, j] / (forestLevels[1] - forestLevels[0]));
                        image.SetPixel(i, j, Color.FromArgb(255 - g, 255, 255 - g));
                    }
                    else// if (pop >0)
                    {
                        terrainMap[i, j] = 2;
                        var b = (int)(255 * pop);
                        image.SetPixel(i, j, Color.FromArgb(255, 255 - b, 255 - b));
                    }

                    /*else
                     * {
                     *  image.SetPixel(i, j, Color.FromArgb(255, 255, 255));
                     * }*/
                    popMap[i, j] = pop;
                }
            }
            pictureBox.Image = image;
            return(getStartPoints(popMap));
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int n = 256;
            int w = 11;
            int h = 4;

            if (smallScaleBox.Text.Length == 0 || largeScaleBox.Text.Length == 0)
            {
                return;
            }
            FractalOptions options = new FractalOptions(parseInt(smallScaleBox), parseInt(largeScaleBox), parseInt(minScaleBox));
            Bitmap         image   = new Bitmap(w * n + 1, h * n + 1);

            WrappingFractal.Initialize(parseInt(seedBox));
            float[,] map = WrappingFractal.fractal(n, h, w, options, FractalWrapMode.Horizontal);
            if (shaveBox.Checked)
            {
                WrappingFractal.shaveEdges(ref map);
            }
            float      ocean  = oceanBar.Value;
            var        levels = FractalUtility.getCutOffLevels(map, new float[] { ocean, oceanBar.Maximum - ocean });
            BitmapData data   = image.LockBits(new Rectangle(0, 0, map.GetLength(0), map.GetLength(1)), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            int[] bitmapColors = new int[map.GetLength(0) * map.GetLength(1)];
            for (int i = 0; i < map.GetLength(0); i++)
            {
                for (int j = 0; j < map.GetLength(1); j++)
                {
                    //Random r = new Random(seed);
                    Color c;
                    if (map[i, j] < levels[0])
                    {
                        c = Color.Blue;
                    }
                    else
                    {
                        c = Color.Green;
                    }

                    int x = i;
                    if (i < map.GetLength(0) / 2)
                    {
                        x += map.GetLength(0) / 2;
                    }
                    else
                    {
                        x -= map.GetLength(0) / 2;
                    }
                    int y = j;
                    //if (j < map.GetLength(1) / 2) y += map.GetLength(1) / 2;
                    //else y -= map.GetLength(1) / 2;

                    bitmapColors[i + j * map.GetLength(0)] = c.ToArgb();
                    //image.SetPixel(i, j, c);
                }
            }
            System.Runtime.InteropServices.Marshal.Copy(bitmapColors, 0, data.Scan0, map.GetLength(0) * map.GetLength(1));
            image.UnlockBits(data);
            image.Save("fractal.bmp");
            setImage(image);
        }
Esempio n. 3
0
        public void OnGenerateMapExecute()
        {
            if (seed <= 0)
            {
                var seedGeneration = new Random();
                Seed = seedGeneration.Next().ToString();
            }
            Random r = new Random(seed);

            var townOptions   = new FractalOptions(townSmallScale, townLargeScale);
            int n             = blocks;
            var popMap        = WrappingFractal.fractal(128, n, n, townOptions, FractalWrapMode.NoWrap, (uint)r.Next());
            var forestOptions = new FractalOptions(forestSmallScale, forestLargeScale);
            var forestMap     = WrappingFractal.fractal(128, n, n, forestOptions, FractalWrapMode.NoWrap, (uint)r.Next());;
            var forestLevels  = FractalUtility.getCutOffLevels(forestMap, new float[] { 100 - forestProportion, forestProportion });
            var bitmap        = new Bitmap(128 * n, 128 * n);
            var terrainMap    = new int[128 * n, 128 * n];

            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    popMap[i, j] = popMap[i, j] - forestMap[i, j];
                }
            }
            var popLevels = FractalUtility.getCutOffLevels(popMap, new float[] { (100 - (forestProportion + townProportion)), townProportion });

            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    popMap[i, j] = popMap[i, j] - popLevels[0];
                    if (popMap[i, j] < 0)
                    {
                        popMap[i, j] = 0;
                    }
                    var pop = (popMap[i, j] / (popLevels[1] - popLevels[0]));
                    if (forestMap[i, j] > forestLevels[0])
                    {
                        terrainMap[i, j] = 2;

                        /*forestMap[i, j] -= forestLevels[0];
                         * pop -= 1f;
                         * var g = (int)(255 * forestMap[i, j] / (forestLevels[1] - forestLevels[0]));
                         * bitmap.SetPixel(i, j, Color.FromArgb(0, 255, 0));*/
                    }
                    else if (pop > 0)
                    {
                        terrainMap[i, j] = 3;

                        /*var b = (int)(255 * pop);
                         * bitmap.SetPixel(i, j, Color.FromArgb(255, 0, 0));
                         */
                    }
                    else
                    {
                        terrainMap[i, j] = 1;
                        //bitmap.SetPixel(i, j, Color.FromArgb(255, 255, 255));
                    }
                    //popMap[i, j] = pop;
                }
            }
            var popCentres = Sanitize(ref terrainMap);

            MapData  = new MapDataPacket(terrainMap, popCentres);
            TownData = null;
        }