//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);
        }
示例#2
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);
        }
示例#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
        public static double value_noise2D(double x, double y, uint seed, InterpTypes type)
        {
            int x0 = fast_floor(x);
            int y0 = fast_floor(y);

            int x1 = x0 + 1;
            int y1 = y0 + 1;

            double xs = Interp((x - x0), type);
            double ys = Interp((y - y0), type);

            return(interp_XY_2(x, y, xs, ys, x0, x1, y0, y1, seed, NoiseFunc.value_noise_2));
        }
示例#9
0
        static double interp(double t, InterpTypes type)
        {
            switch (type)
            {
            case InterpTypes.NONE: return(noInterp(t));

            case InterpTypes.LINEAR: return(linearInterp(t));

            case InterpTypes.QUINTIC: return(quinticInterp(t));

            case InterpTypes.CUBIC: return(hermiteInterp(t));
            }

            return(noInterp(t));
        }
示例#10
0
        private static double Interp(double t, InterpTypes type)
        {
            switch (type)
            {
            case InterpTypes.NONE:
                return(NoInterp(t));

            case InterpTypes.LINEAR:
                return(LinearInterp(t));

            case InterpTypes.QUINTIC:
                return(QuinticInterp(t));

            case InterpTypes.CUBIC:
                return(HermiteInterp(t));
            }
            return(NoInterp(t));
        }
示例#11
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);
        }
示例#12
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);
        }
示例#13
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);
        }
示例#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
        public static double simplex_noise2D(double x, double y, uint seed, InterpTypes interp)
        {
            double s = (x + y) * F2;
            int    i = fast_floor(x + s);
            int    j = fast_floor(y + s);

            double t  = (i + j) * G2;
            double X0 = i - t;
            double Y0 = j - t;
            double x0 = x - X0;
            double y0 = y - Y0;

            int i1, j1;

            if (x0 > y0)
            {
                i1 = 1; j1 = 0;
            }
            else
            {
                i1 = 0; j1 = 1;
            }

            double x1 = x0 - i1 + G2;
            double y1 = y0 - j1 + G2;
            double x2 = x0 - 1.0 + 2.0 * G2;
            double y2 = y0 - 1.0 + 2.0 * G2;

            // Hash the triangle coordinates to index the gradient table
            uint h0 = hash_coords_2(i, j, seed);
            uint h1 = hash_coords_2(i + i1, j + j1, seed);
            uint h2 = hash_coords_2(i + 1, j + 1, seed);

            // Now, index the tables
            double[] g0 = gradient2D_lut[h0];
            double[] g1 = gradient2D_lut[h1];
            double[] g2 = gradient2D_lut[h2];

            double n0, n1, n2;
            // Calculate the contributions from the 3 corners
            double t0 = 0.5 - x0 * x0 - y0 * y0;

            if (t0 < 0)
            {
                n0 = 0;
            }
            else
            {
                t0 *= t0;
                n0  = t0 * t0 * array_dot2(g0, x0, y0);
            }

            double t1 = 0.5 - x1 * x1 - y1 * y1;

            if (t1 < 0)
            {
                n1 = 0;
            }
            else
            {
                t1 *= t1;
                n1  = t1 * t1 * array_dot2(g1, x1, y1);
            }

            double t2 = 0.5 - x2 * x2 - y2 * y2;

            if (t2 < 0)
            {
                n2 = 0;
            }
            else
            {
                t2 *= t2;
                n2  = t2 * t2 * array_dot2(g2, x2, y2);
            }

            // Add contributions together
            return((70.0 * (n0 + n1 + n2)) * 1.42188695 + 0.001054489);
        }
示例#16
0
 public static double gradval_noise2D(double x, double y, uint seed, InterpTypes type)
 {
     return value_noise2D(x, y, seed, type) + gradient_noise2D(x, y, seed, type);
 }
示例#17
0
 public static double white_noise2D(double x, double y, uint seed, InterpTypes interp)
 {
     byte hash = (byte) compute_hash_double_2(x,y,seed);
     return whitenoise_lut[hash];
 }
示例#18
0
        public static double white_noise2D(double x, double y, uint seed, InterpTypes interp)
        {
            byte hash = (byte)compute_hash_double_2(x, y, seed);

            return(_whitenoiseLut[hash]);
        }
示例#19
0
 public static double gradval_noise2D(double x, double y, uint seed, InterpTypes type)
 {
     return(value_noise2D(x, y, seed, type) + gradient_noise2D(x, y, seed, type));
 }
示例#20
0
        public static double value_noise2D(double x, double y, uint seed, InterpTypes type)
        {
            int x0=fast_floor(x);
            int y0=fast_floor(y);

            int x1=x0+1;
            int y1=y0+1;

            double xs = interp((x - (double)x0), type);
            double ys = interp((y - (double)y0), type);

            return interp_XY_2(x,y,xs,ys,x0,x1,y0,y1,seed,NoiseFunc.value_noise_2);
        }
示例#21
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);
     }
 }
示例#22
0
        static double interp(double t, InterpTypes type)
        {
            switch (type)
            {
                case InterpTypes.NONE: return noInterp(t);
                case InterpTypes.LINEAR: return linearInterp(t);
                case InterpTypes.QUINTIC: return quinticInterp(t);
                case InterpTypes.CUBIC: return hermiteInterp(t);
            }

            return noInterp(t);
        }
示例#23
0
 private void SetAllSourceTypes(BasisTypes basis_type, InterpTypes interp)
 {
     for(int i=0; i < MaxSources; i++)
         m_basis[i] = new BasisFunction(basis_type, interp);
 }