//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); }
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); }
private void SetAllSourceTypes(BasisTypes basis_type, InterpTypes interp) { for (int i = 0; i < MaxSources; i++) { m_basis[i] = new BasisFunction(basis_type, interp); } }
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); } }
public BasisFunction(BasisTypes type, InterpTypes interp, uint seed, double angle) { _type = type; _interp = interp; _seed = seed; SetAngle(angle); SetMagicNumbers(type); }
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)); }
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)); }
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)); }
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); }
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); }
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); }
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; }
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); }
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); }
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]; }
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]); }
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)); }
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); }
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); } }
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); }
private void SetAllSourceTypes(BasisTypes basis_type, InterpTypes interp) { for(int i=0; i < MaxSources; i++) m_basis[i] = new BasisFunction(basis_type, interp); }