using System;
namespace LibNoise.Generator
{
///
/// Provides a noise module that outputs concentric spheres. [GENERATOR]
///
public class Spheres : ModuleBase
{
#region Fields
private double _frequency = 1.0;
#endregion
#region Constructors
///
/// Initializes a new instance of Spheres.
///
public Spheres()
: base(0)
{
}
///
/// Initializes a new instance of Spheres.
///
/// The frequency of the concentric spheres.
public Spheres(double frequency)
: base(0)
{
Frequency = frequency;
}
#endregion
#region Properties
///
/// Gets or sets the frequency of the concentric spheres.
///
public double Frequency
{
get { return _frequency; }
set { _frequency = value; }
}
#endregion
#region ModuleBase Members
///
/// Returns the output value for the given input coordinates.
///
/// The input coordinate on the x-axis.
/// The input coordinate on the y-axis.
/// The input coordinate on the z-axis.
/// The resulting output value.
public override double GetValue(double x, double y, double z)
{
x *= _frequency;
y *= _frequency;
z *= _frequency;
var dfc = Math.Sqrt(x * x + y * y + z * z);
var dfss = dfc - Math.Floor(dfc);
var dfls = 1.0 - dfss;
var nd = Math.Min(dfss, dfls);
return 1.0 - (nd * 4.0);
}
#endregion
}
}