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); }
//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); }
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); }
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; } ; }
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 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; }; }
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); } }
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; }
private void SetAllSourceTypes(BasisTypes basis_type, InterpTypes interp) { for(int i=0; i < MaxSources; i++) m_basis[i] = new BasisFunction(basis_type, interp); }