public static IFunction2D FractionalBrownianMotion(this INoiseProvider provider, Random rng, double scale, int octaves, double persistence = 0.5, double lacunarity = 2.0, Func<double, double> octaveModifier = null, double? xPeriod = null, double? yPeriod = null, SampleMode mode = SampleMode.Sample2D) { return new FractionalBrownianMotionFunction(provider, rng, scale, octaves, persistence, lacunarity, octaveModifier, xPeriod, yPeriod, mode); }
private void buttonGenerate_Click(object sender, EventArgs e) { if (_workerThread != null) { _workerThread.Abort(); _workerThread = null; buttonGenerate.Text = "Generate Images"; return; } try { _octaves = GetIntValue(textBoxOctaves, "Octaves", 0, 51); _scale = GetDoubleValue(textBoxScale, "Scale", 0.0); _persistence = GetDoubleValue(textBoxPersistence, "Persistence", 0.0); _lacunarity = GetDoubleValue(textBoxLacunarity, "Lacunarity", 0.0); _size = GetIntValue(textBoxSize, "Size", 0, 10001); _power = GetDoubleValue(textBoxPower, "Power", 0.0); _mode = (SampleMode)comboBoxMode.SelectedIndex; _absoluteValue = checkBoxAbsoluteValue.Checked; _normalize = checkBoxNormalize.Checked; } catch (Exception exception) { MessageBox.Show(exception.Message, "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _workerThread = new Thread(DoWork); // Give higher thread priority for more consistent benchmarks. _workerThread.Priority = ThreadPriority.AboveNormal; _workerThread.IsBackground = true; _workerThread.Start(); pictureBoxSimplex.Image = null; pictureBoxSimpletic.Image = null; pictureBoxOpenSimplex.Image = null; buttonSaveSimplex.Enabled = false; buttonSaveSimpletic.Enabled = false; buttonSaveOpenSimplex.Enabled = false; buttonSaveComparison.Enabled = false; textBoxSimplex.Text = "Loading..."; textBoxSimpletic.Text = "Loading..."; textBoxOpenSimplex.Text = "Loading..."; buttonGenerate.Text = "Cancel"; }
public FractionalBrownianMotionFunction(INoiseProvider provider, Random rng, double scale, int octaves, double persistence = 0.5, double lacunarity = 2.0, Func<double, double> octaveModifier = null, double? xPeriod = null, double? yPeriod = null, SampleMode mode = SampleMode.Sample2D) { _octaveModifier = octaveModifier; _octaves = new Tuple<double, IFunction2D>[octaves]; bool tiling = xPeriod != null || yPeriod != null; if (tiling && xPeriod == null) { xPeriod = yPeriod; } if (tiling && yPeriod == null) { yPeriod = xPeriod; } _maxAmplitude = 0.0; var amplitude = 1.0; var frequency = scale; for (var i = 0; i < octaves; i++) { IFunction2D noise; switch (mode) { case SampleMode.Sample2D: noise = provider.Create2D(rng, frequency); break; case SampleMode.Slice3D: noise = provider.Slice3D(rng, frequency); break; case SampleMode.Slice4D: noise = provider.Slice4D(rng, frequency); break; case SampleMode.Tileable2D: noise = provider.Create2D(rng, frequency, xPeriod.Value, yPeriod.Value); break; default: throw new InvalidOperationException(); } _octaves[i] = Tuple.Create(amplitude, noise); _maxAmplitude += amplitude; amplitude *= persistence; frequency *= lacunarity; } }
/// <summary> /// /// </summary> /// <param name="interval"></param> /// <param name="countX"></param> /// <param name="countY"></param> /// <param name="wrapModeX"></param> /// <param name="wrapModeY"></param> /// <param name="sampleMode"></param> public GridVectorField2d(Interval2d interval, int countX, int countY, WrapMode wrapModeX, WrapMode wrapModeY, SampleMode sampleMode = SampleMode.Linear) : base(interval, countX, countY, wrapModeX, wrapModeY, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="grid"></param> /// <param name="sampleMode"></param> public GridField3d(Grid3d grid, SampleMode sampleMode = SampleMode.Linear) : base(grid) { _values = new T[Count]; SampleMode = sampleMode; }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <param name="sampleMode"></param> public GridVectorField2d(Grid2d other, SampleMode sampleMode = SampleMode.Linear) : base(other, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="origin"></param> /// <param name="scale"></param> /// <param name="countX"></param> /// <param name="countY"></param> /// <param name="wrapModeX"></param> /// <param name="wrapModeY"></param> /// <param name="sampleMode"></param> public GridVectorField2d(Vec2d origin, Vec2d scale, int countX, int countY, WrapMode wrapModeX, WrapMode wrapModeY, SampleMode sampleMode = SampleMode.Linear) : base(origin, scale, countX, countY, wrapModeX, wrapModeY, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="origin"></param> /// <param name="scale"></param> /// <param name="countX"></param> /// <param name="countY"></param> /// <param name="countZ"></param> /// <param name="wrapModeX"></param> /// <param name="wrapModeY"></param> /// <param name="wrapModeZ"></param> /// <param name="sampleMode"></param> public GridScalarField3d(Vec3d origin, Vec3d scale, int countX, int countY, int countZ, WrapMode wrapModeX, WrapMode wrapModeY, WrapMode wrapModeZ, SampleMode sampleMode = SampleMode.Linear) : base(origin, scale, countX, countY, countZ, wrapModeX, wrapModeY, wrapModeZ, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="interval"></param> /// <param name="countX"></param> /// <param name="countY"></param> /// <param name="countZ"></param> /// <param name="wrapMode"></param> /// <param name="sampleMode"></param> public GridScalarField3d(Interval3d interval, int countX, int countY, int countZ, WrapMode wrapMode = WrapMode.Clamp, SampleMode sampleMode = SampleMode.Linear) : base(interval, countX, countY, countZ, wrapMode, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <param name="sampleMode"></param> public GridScalarField3d(Grid3d other, SampleMode sampleMode = SampleMode.Linear) : base(other, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="origin"></param> /// <param name="scale"></param> /// <param name="countX"></param> /// <param name="countY"></param> /// <param name="wrapMode"></param> /// <param name="sampleMode"></param> public GridScalarField2d(Vec2d origin, Vec2d scale, int countX, int countY, WrapMode wrapMode = WrapMode.Clamp, SampleMode sampleMode = SampleMode.Linear) : base(origin, scale, countX, countY, wrapMode, sampleMode) { }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LinearClicked(object sender, EventArgs e) { _sampleMode = SampleMode.Linear; ExpireSolution(true); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NearestClicked(object sender, EventArgs e) { _sampleMode = SampleMode.Nearest; ExpireSolution(true); }
/// <summary> /// /// </summary> /// <param name="origin"></param> /// <param name="scale"></param> /// <param name="countX"></param> /// <param name="countY"></param> /// <param name="countZ"></param> /// <param name="wrapMode"></param> /// <param name="sampleMode"></param> public GridVectorField3d(Vec3d origin, Vec3d scale, int countX, int countY, int countZ, WrapMode wrapMode = WrapMode.Clamp, SampleMode sampleMode = SampleMode.Linear) : base(origin, scale, countX, countY, countZ, wrapMode, sampleMode) { }