Пример #1
0
        public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType, int?octaves, double?frequency, uint?seed)
        {
            if (octaves == null)
            {
                octaves = 8;
            }

            if (frequency == null)
            {
                frequency = 1.0;
            }

            if (seed == null)
            {
                seed = 10000;
            }

            m_lacunarity = 2.0;
            SetOctaves((int)octaves);
            m_frequency = (double)frequency;
            SetType(type);
            SetAllSourceTypes(basisType, interpType);

            SetSeed((uint)seed);
        }
Пример #2
0
 //public BasisFunction()
 //{
 //    this.Type = BasisTypes.GRADIENT;
 //    this.Interp = InterpTypes.QUINTIC;
 //    setMagicNumbers(this.Type);
 //    SetSeed(1000);
 //}
 public BasisFunction(BasisTypes type, InterpTypes interp)
 {
     this.Type = type;
     this.Interp = interp;
     setMagicNumbers(type);
     SetSeed(1000);
 }
Пример #3
0
 private void SetAllSourceTypes(BasisTypes basis_type, InterpTypes interp)
 {
     for (int i = 0; i < MaxSources; i++)
     {
         m_basis[i] = new BasisFunction(basis_type, interp);
     }
 }
Пример #4
0
        //public BasisFunction()
        //{
        //    this.Type = BasisTypes.GRADIENT;
        //    this.Interp = InterpTypes.QUINTIC;
        //    setMagicNumbers(this.Type);

        //    SetSeed(1000);
        //}

        public BasisFunction(BasisTypes type, InterpTypes interp)
        {
            this.Type   = type;
            this.Interp = interp;
            setMagicNumbers(type);
            SetSeed(1000);
        }
Пример #5
0
 private void SetAllSourceTypes(BasisTypes basisType, InterpTypes interp, uint seed,
                                double angle)
 {
     for (int i = 0; i < MaxSources; i++)
     {
         _basis[i] = new BasisFunction(basisType, interp, (uint)(seed + i * 300), angle);
     }
 }
Пример #6
0
 public BasisFunction(BasisTypes type, InterpTypes interp, uint seed, double angle)
 {
     _type = type;
     _interp = interp;
     _seed = seed;
     SetAngle(angle);
     SetMagicNumbers(type);
 }
Пример #7
0
 public BasisFunction(BasisTypes type, InterpTypes interp, uint seed, double angle)
 {
     _type   = type;
     _interp = interp;
     _seed   = seed;
     SetAngle(angle);
     SetMagicNumbers(type);
 }
Пример #8
0
        private void setMagicNumbers(BasisTypes type)
        {
            // This function is a damned hack.
            // The underlying noise functions don't return values in the range [-1,1] cleanly, and the ranges vary depending
            // on basis type and dimensionality. There's probably a better way to correct the ranges, but for now I'm just
            // setting he magic numbers m_scale and m_offset manually to empirically determined magic numbers.
            switch (type)
            {
            case BasisTypes.VALUE:
            {
                m_scale[0] = 1.0; m_offset[0] = 0.0;
                m_scale[1] = 1.0; m_offset[1] = 0.0;
                m_scale[2] = 1.0; m_offset[2] = 0.0;
                m_scale[3] = 1.0; m_offset[3] = 0.0;
            } break;

            case BasisTypes.GRADIENT:
            {
                m_scale[0] = 1.86848; m_offset[0] = -0.000118;
                m_scale[1] = 1.85148; m_offset[1] = -0.008272;
                m_scale[2] = 1.64127; m_offset[2] = -0.01527;
                m_scale[3] = 1.92517; m_offset[3] = 0.03393;
            } break;

            case BasisTypes.GRADVAL:
            {
                m_scale[0] = 0.6769; m_offset[0] = -0.00151;
                m_scale[1] = 0.6957; m_offset[1] = -0.133;
                m_scale[2] = 0.74622; m_offset[2] = 0.01916;
                m_scale[3] = 0.7961; m_offset[3] = -0.0352;
            } break;

            case BasisTypes.WHITE:
            {
                m_scale[0] = 1.0; m_offset[0] = 0.0;
                m_scale[1] = 1.0; m_offset[1] = 0.0;
                m_scale[2] = 1.0; m_offset[2] = 0.0;
                m_scale[3] = 1.0; m_offset[3] = 0.0;
            } break;

            default:
            {
                m_scale[0] = 1.0; m_offset[0] = 0.0;
                m_scale[1] = 1.0; m_offset[1] = 0.0;
                m_scale[2] = 1.0; m_offset[2] = 0.0;
                m_scale[3] = 1.0; m_offset[3] = 0.0;
            } break;
            }
            ;
        }
Пример #9
0
        public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType, int? octaves, double? frequency, uint? seed)
        {
            if (octaves == null)
                octaves = 8;

            if (frequency == null)
                frequency = 1.0;

            if (seed == null)
                seed = 10000;

            SetOctaves((int)octaves);
            m_frequency = (double)frequency;
            m_lacunarity = 2;
            SetType(type);
            SetAllSourceTypes(basisType, interpType);

            SetSeed((uint)seed);
        }
Пример #10
0
        public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType,
            int? octaves = null, double? frequency = null, uint? seed = null,
            double? angle = null, double? lacunarity = null)
        {
            if (octaves == null)
            {
                octaves = 1;
            }

            if (frequency == null)
            {
                frequency = 1.0;
            }

            if (seed == null)
            {
                seed = 10000;
            }

            if (angle == null)
            {
                angle = 0;
            }

            if (lacunarity == null)
            {
                lacunarity = 2;
            }

            _frequency = frequency.Value;
            _lacunarity = lacunarity.Value;

            SetOctaves(octaves.Value);
            SetType(type);
            SetAllSourceTypes(basisType, interpType, seed.Value, angle.Value);
        }
Пример #11
0
        public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType,
                       int?octaves  = null, double?frequency  = null, uint?seed = null,
                       double?angle = null, double?lacunarity = null)
        {
            if (octaves == null)
            {
                octaves = 1;
            }

            if (frequency == null)
            {
                frequency = 1.0;
            }

            if (seed == null)
            {
                seed = 10000;
            }

            if (angle == null)
            {
                angle = 0;
            }

            if (lacunarity == null)
            {
                lacunarity = 2;
            }

            _frequency  = frequency.Value;
            _lacunarity = lacunarity.Value;

            SetOctaves(octaves.Value);
            SetType(type);
            SetAllSourceTypes(basisType, interpType, seed.Value, angle.Value);
        }
Пример #12
0
        private void setMagicNumbers(BasisTypes type)
        {
            // This function is a damned hack.
            // The underlying noise functions don't return values in the range [-1,1] cleanly, and the ranges vary depending
            // on basis type and dimensionality. There's probably a better way to correct the ranges, but for now I'm just
            // setting he magic numbers m_scale and m_offset manually to empirically determined magic numbers.
            switch(type)
            {
                case BasisTypes.VALUE:
                {
                    m_scale[0]=1.0; m_offset[0]=0.0;
                    m_scale[1]=1.0; m_offset[1]=0.0;
                    m_scale[2]=1.0; m_offset[2]=0.0;
                    m_scale[3]=1.0; m_offset[3]=0.0;
                } break;

                case BasisTypes.GRADIENT:
                {
                    m_scale[0]=1.86848; m_offset[0]=-0.000118;
                    m_scale[1]=1.85148; m_offset[1]=-0.008272;
                    m_scale[2]=1.64127; m_offset[2]=-0.01527;
                    m_scale[3]=1.92517; m_offset[3]=0.03393;
                } break;

                case BasisTypes.GRADVAL:
                {
                    m_scale[0]=0.6769; m_offset[0]=-0.00151;
                    m_scale[1]=0.6957; m_offset[1]=-0.133;
                    m_scale[2]=0.74622; m_offset[2]=0.01916;
                    m_scale[3]=0.7961; m_offset[3]=-0.0352;
                } break;

                case BasisTypes.WHITE:
                {
                    m_scale[0]=1.0; m_offset[0]=0.0;
                    m_scale[1]=1.0; m_offset[1]=0.0;
                    m_scale[2]=1.0; m_offset[2]=0.0;
                    m_scale[3]=1.0; m_offset[3]=0.0;
                } break;

                default:
                {
                    m_scale[0]=1.0; m_offset[0]=0.0;
                    m_scale[1]=1.0; m_offset[1]=0.0;
                    m_scale[2]=1.0; m_offset[2]=0.0;
                    m_scale[3]=1.0; m_offset[3]=0.0;
                } break;
            };
        }
Пример #13
0
 private void SetAllSourceTypes(BasisTypes basisType, InterpTypes interp, uint seed,
     double angle)
 {
     for (int i = 0; i < MaxSources; i++)
     {
         _basis[i] = new BasisFunction(basisType, interp, (uint) (seed + i * 300), angle);
     }
 }
Пример #14
0
        private unsafe void BtnGenerateLabyrinthClick(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            FractalType type    = (FractalType)cbLabyrinthType.SelectedItem;
            BasisTypes  basis   = (BasisTypes)cbLabyrinthBasis.SelectedItem;
            InterpTypes interp  = (InterpTypes)cbLabyrinthInterp.SelectedItem;
            int?        octaves = !string.IsNullOrEmpty(tbLabyrinthOctaves.Text)
                ? int.Parse(tbLabyrinthOctaves.Text)
                : (int?)null;
            double?frequency = !string.IsNullOrEmpty(tbLabyrinthFrequency.Text)
                ? double.Parse(tbLabyrinthFrequency.Text)
                : (double?)null;
            double?angle = !string.IsNullOrEmpty(tbLabyrinthAngle.Text)
                ? double.Parse(tbLabyrinthAngle.Text)
                : (double?)null;
            double?lacunarity = !string.IsNullOrEmpty(tbLabyrinthLacunarity.Text)
                ? double.Parse(tbLabyrinthLacunarity.Text)
                : (double?)null;

            _labOldSeed = cbLabyrinthRnd.Checked ? (uint?)Environment.TickCount : _labOldSeed;

            ModuleBase moduleBase = new Fractal(type, basis, interp, octaves, frequency, _labOldSeed,
                                                angle, lacunarity);

            if (chkLabyrinthAC.Checked)
            {
                double        acLow    = double.Parse(tbLabyrinthACLow.Text);
                double        acHigh   = double.Parse(tbLabyrinthACHigh.Text);
                CombinerTypes combType = (CombinerTypes)cbLabyrinthACCombine.SelectedItem;
                AutoCorrect   correct  = new AutoCorrect(moduleBase, acLow, acHigh);
                moduleBase = new Combiner(combType, correct, moduleBase);
            }

//            Bias bias = new Bias(moduleBase, 0.01);
//            Gradient gradient = new Gradient(0, 0, 50, 100);
//            moduleBase = new TranslatedDomain(moduleBase, gradient, bias);

            if (chkLabyrinthSel.Checked)
            {
                double selLow       = double.Parse(tbLabyrinthSelLow.Text);
                double selHigh      = double.Parse(tbLabyrinthSelHigh.Text);
                double selThreshold = double.Parse(tbLabyrinthSelThreshold.Text);
                double?selFalloff   = !string.IsNullOrEmpty(tbLabyrinthSelFalloff.Text)
                    ? double.Parse(tbLabyrinthSelFalloff.Text)
                    : (double?)null;
                moduleBase = new Select(moduleBase, selLow, selHigh, selThreshold, selFalloff);
            }

            if (pbLabyrinth.Image != null)
            {
                pbLabyrinth.Image.Dispose();
            }

            ushort     width = 500, height = 500;
            Bitmap     bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
            BitmapData data   = bitmap.LockBits(new Rectangle(0, 0, width, height),
                                                ImageLockMode.ReadWrite, bitmap.PixelFormat);

            byte *pRoughMap = (byte *)Memory.HeapAlloc(width * height);

            Parallel.For(0, height, y =>
            {
                int *row = (int *)data.Scan0 + (y * data.Stride) / 4;
                Parallel.For(0, width, x =>
                {
                    double p   = (double)x / width;
                    double q   = (double)y / height;
                    double val = moduleBase.Get(p, q);
                    pRoughMap[y * width + x] = (byte)Math.Abs(val - 1);
                    Color color = Color.Black.Lerp(Color.White, val);
                    row[x]      = color.ToArgb();
                });
            });

            using (ServerMap map = new ServerMap(width, height, 0, pRoughMap))
            {
                map.SaveToFile("RK.save");
            }
            Memory.HeapFree(pRoughMap);

            bitmap.UnlockBits(data);
            pbLabyrinth.Image = bitmap;

            Cursor = DefaultCursor;
        }
Пример #15
0
 private void SetAllSourceTypes(BasisTypes basis_type, InterpTypes interp)
 {
     for(int i=0; i < MaxSources; i++)
         m_basis[i] = new BasisFunction(basis_type, interp);
 }