コード例 #1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 0; i < nudCount.Value; i++)
            {
                PerlinNoise3D perlinNoise3D = new PerlinNoise3D(_seed);

                for (int xChunk = 0; xChunk < _dimension; xChunk += 16)
                {

                    for (int zChunk = 0; zChunk < _dimension; zChunk += 16)
                    {

                        int[,] buffer = new int[16, 16];
                        for (int y = 0; y < _height; y++)
                        {
                            Single heightmod = (Single)((((Double)y / _height) - 0.5) * 2);
                            for (int x = 0; x < 16; x++)
                                for (int z = 0; z < 16; z++)
                                {
                                    Single value = heightmod +
                                                   perlinNoise3D.GetValue(x + xChunk, y, z + zChunk, .01875f, 1f, .5f, 8);
                                    if (value <= 0)
                                        buffer[x, z] = y;
                                }
                        }
                        try
                        {
                            using (Graphics gBmp = Graphics.FromImage(_bmp))
                            {
                                for (int x = 0; x < 16; x++)
                                    for (int z = 0; z < 16; z++)
                                    {
                                        int y = buffer[x, z];
                                        Color color = Color.FromArgb(y * 2, y * 2, y * 2);
                                        using (Pen pen = new Pen(color))
                                        {
                                            gBmp.DrawLine(pen, x + xChunk, z + zChunk, x + xChunk + 1, z + zChunk);
                                            if (y < 65)
                                            {
                                                using (
                                                    Pen pen2 =
                                                        new Pen(Color.FromArgb(_a, _r, _g, _b)))
                                                    gBmp.DrawLine(pen2, x + xChunk, z + zChunk, x + xChunk + 1,
                                                                  z + zChunk);
                                            }
                                        }
                                    }
                            }
                        }
                        catch
                        {
                        }
                        backgroundWorker1.ReportProgress(++prc);
                    }
                }
            }
        }
コード例 #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 0; i < nudCount.Value; i++)
            {
                PerlinNoise3D perlinNoise3D = new PerlinNoise3D(_seed);

                for (int xChunk = 0; xChunk < _dimension; xChunk += 16)
                {
                    for (int zChunk = 0; zChunk < _dimension; zChunk += 16)
                    {
                        int[,] buffer = new int[16, 16];
                        for (int y = 0; y < _height; y++)
                        {
                            Single heightmod = (Single)((((Double)y / _height) - 0.5) * 2);
                            for (int x = 0; x < 16; x++)
                            {
                                for (int z = 0; z < 16; z++)
                                {
                                    Single value = heightmod +
                                                   perlinNoise3D.GetValue(x + xChunk, y, z + zChunk, .01875f, 1f, .5f, 8);
                                    if (value <= 0)
                                    {
                                        buffer[x, z] = y;
                                    }
                                }
                            }
                        }
                        try
                        {
                            using (Graphics gBmp = Graphics.FromImage(_bmp))
                            {
                                for (int x = 0; x < 16; x++)
                                {
                                    for (int z = 0; z < 16; z++)
                                    {
                                        int   y     = buffer[x, z];
                                        Color color = Color.FromArgb(y * 2, y * 2, y * 2);
                                        using (Pen pen = new Pen(color))
                                        {
                                            gBmp.DrawLine(pen, x + xChunk, z + zChunk, x + xChunk + 1, z + zChunk);
                                            if (y < 65)
                                            {
                                                using (
                                                    Pen pen2 =
                                                        new Pen(Color.FromArgb(_a, _r, _g, _b)))
                                                    gBmp.DrawLine(pen2, x + xChunk, z + zChunk, x + xChunk + 1,
                                                                  z + zChunk);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        backgroundWorker1.ReportProgress(++prc);
                    }
                }
            }
        }
コード例 #3
0
        private void BackgroundWorker1DoWork(object sender, DoWorkEventArgs e)
        {
            _dimension = Convert.ToInt32(txtDimension.Text);
            _height    = Convert.ToInt32(txtHeigth.Text);
            _seed      = Convert.ToInt32(txtSeed.Text);

            _bmp = new Bitmap(_dimension, _dimension, PixelFormat.Format32bppArgb);
            pictureBox1.Image = _bmp;


            var cmb = e.Argument;

            PerlinNoise3D perlinNoise3D = new PerlinNoise3D(_seed);


            for (int xChunk = 0; xChunk < _dimension; xChunk += 16)
            {
                InvokeIfRequired(lblxChunks, (MethodInvoker) delegate
                {
                    lblxChunks.Text = xChunk.ToString();
                });

                for (int zChunk = 0; zChunk < _dimension; zChunk += 16)
                {
                    _overallzChunks += 16;

                    InvokeIfRequired(lblzChunks, (MethodInvoker) delegate
                    {
                        lblzChunks.Text = string.Format("{0}|{1}",
                                                        zChunk,
                                                        _overallzChunks);
                    });


                    int[,] buffer = new int[16, 16];

                    for (int y = 0; y < _height; y++)
                    {
                        Single heightmod = (Single)((((Double)y / _height) - 0.5) * 2);

                        for (int x = 0; x < 16; x++)
                        {
                            for (int z = 0; z < 16; z++)
                            {
                                Single value = heightmod +
                                               perlinNoise3D.GetValue(x + xChunk, y, z + zChunk, .01875f, 1f, .5f, 8);

                                if (value <= 0)
                                {
                                    buffer[x, z] = y;
                                }
                            }
                        }
                    }
                    try
                    {
                        using (Graphics gBmp = Graphics.FromImage(_bmp))
                        {
                            for (int x = 0; x < 16; x++)
                            {
                                for (int z = 0; z < 16; z++)
                                {
                                    int   y     = buffer[x, z];
                                    Color color = Color.FromArgb(y * 2, y * 2, y * 2);
                                    using (Pen pen = new Pen(color))
                                    {
                                        gBmp.DrawLine(pen, x + xChunk, z + zChunk, x + xChunk + 1, z + zChunk);

                                        if (y < 65)
                                        {
                                            if (!_useCustomColor)
                                            {
                                                using (
                                                    Pen pen2 =
                                                        new Pen(Color.FromArgb(Convert.ToInt32(txtAlpha.Text),
                                                                               Color.FromName(
                                                                                   _colorList[(int)cmb].
                                                                                   Name))))
                                                    gBmp.DrawLine(pen2, x + xChunk, z + zChunk, x + xChunk + 1,
                                                                  z + zChunk);
                                            }
                                            else
                                            {
                                                using (
                                                    Pen pen2 =
                                                        new Pen(Color.FromArgb(_a, _r, _g, _b)))
                                                    gBmp.DrawLine(pen2, x + xChunk, z + zChunk, x + xChunk + 1,
                                                                  z + zChunk);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch
                    { }

                    InvokeIfRequired(pictureBox1, (MethodInvoker)(() => pictureBox1.Refresh()));
                }
            }
        }
コード例 #4
0
        private void BackgroundWorker1DoWork(object sender, DoWorkEventArgs e)
        {
            _dimension = Convert.ToInt32(txtDimension.Text);
            _height = Convert.ToInt32(txtHeigth.Text);
            _seed = Convert.ToInt32(txtSeed.Text);

            _bmp = new Bitmap(_dimension, _dimension, PixelFormat.Format32bppArgb);
            pictureBox1.Image = _bmp;


            var cmb = e.Argument;

            PerlinNoise3D perlinNoise3D = new PerlinNoise3D(_seed);


            for (int xChunk = 0; xChunk < _dimension; xChunk += 16)
            {

                InvokeIfRequired(lblxChunks, (MethodInvoker)delegate
                {
                    lblxChunks.Text = xChunk.ToString();
                });

                for (int zChunk = 0; zChunk < _dimension; zChunk += 16)
                {
                    _overallzChunks += 16;

                    InvokeIfRequired(lblzChunks, (MethodInvoker)delegate
                    {
                        lblzChunks.Text = string.Format("{0}|{1}",
                                                        zChunk,
                                                        _overallzChunks);
                    });


                    int[,] buffer = new int[16, 16];

                    for (int y = 0; y < _height; y++)
                    {
                        Single heightmod = (Single)((((Double)y / _height) - 0.5) * 2);

                        for (int x = 0; x < 16; x++)
                            for (int z = 0; z < 16; z++)
                            {
                                Single value = heightmod +
                                               perlinNoise3D.GetValue(x + xChunk, y, z + zChunk, .01875f, 1f, .5f, 8);

                                if (value <= 0)
                                    buffer[x, z] = y;
                            }
                    }
                    try
                    {
                        using (Graphics gBmp = Graphics.FromImage(_bmp))
                        {
                            for (int x = 0; x < 16; x++)
                                for (int z = 0; z < 16; z++)
                                {
                                    int y = buffer[x, z];
                                    Color color = Color.FromArgb(y * 2, y * 2, y * 2);
                                    using (Pen pen = new Pen(color))
                                    {
                                        gBmp.DrawLine(pen, x + xChunk, z + zChunk, x + xChunk + 1, z + zChunk);

                                        if (y < 65)
                                        {
                                            if (!_useCustomColor)
                                            {
                                                using (
                                                    Pen pen2 =
                                                        new Pen(Color.FromArgb(Convert.ToInt32(txtAlpha.Text),
                                                                               Color.FromName(
                                                                                   _colorList[(int)cmb].
                                                                                       Name))))
                                                    gBmp.DrawLine(pen2, x + xChunk, z + zChunk, x + xChunk + 1,
                                                                  z + zChunk);
                                            }
                                            else
                                            {
                                                using (
                                                    Pen pen2 =
                                                        new Pen(Color.FromArgb(_a, _r, _g, _b)))
                                                    gBmp.DrawLine(pen2, x + xChunk, z + zChunk, x + xChunk + 1,
                                                                  z + zChunk);

                                            }
                                        }
                                    }
                                }
                        }

                    }
                    catch
                    { }

                    InvokeIfRequired(pictureBox1, (MethodInvoker)(() => pictureBox1.Refresh()));
                }
            }
        }