001package squidpony.squidmath;
002
003/**
004 * Delegates to {@link ClassicNoise} methods and always uses the same seed (123456789); that means this produces 
005 * "Classic Perlin Noise" and not Simplex Noise (both were created by Ken Perlin). ClassicNoise provides more options
006 * because it implements {@link squidpony.squidmath.Noise.Noise2D} and other Noise interfaces; you can use Noise2D and
007 * its relatives with classes like {@link squidpony.squidmath.Noise.Ridged2D}. You could also use {@link FastNoise} with
008 * {@link FastNoise#PERLIN_FRACTAL} as its noiseType, which includes features like adding together multiple octaves or
009 * the above ridged noise. This is pretty much here as a bare-bones, basic noise generator.
010 * <br>
011 * This formerly produced Simplex noise, which was incredibly confusing; if you want that type of noise you should use
012 * {@link SeededNoise}. To exactly reproduce the old PerlinNoise methods, you can call
013 * {@code return SeededNoise.noise(x * 0.11709966304863834, y * 0.11709966304863834, 123456789)} for 2D,
014 * {@code return SeededNoise.noise(x * 0.11709966304863834, y * 0.11709966304863834, z * 0.11709966304863834, 123456789)} for 3D, or
015 * {@code return SeededNoise.noise(x * 0.11709966304863834, y * 0.11709966304863834, z * 0.11709966304863834, w * 0.11709966304863834, 123456789)} for 4D.
016 * {@code 0.11709966304863834} is just the frequency this uses; it's {@code 1.0 / Math.E / Math.PI}, which is meant to
017 * hit an integer multiple very rarely.
018 */
019public class PerlinNoise {
020
021    /**
022     * This class simply calls methods from {@link ClassicNoise} and multiplies the inputs by 0.11709966304863834, or
023     * {@code 1.0 / Math.E / Math.PI}. Where a seed is used, it's always 123456789.
024     */
025    public static final double SCALE = 1.0 / Math.E / Math.PI;
026
027    protected PerlinNoise()
028    {
029
030    }
031    
032    /**
033     * Delegates to {@link ClassicNoise#getNoiseWithSeed(double, double, long)}; multiplies its inputs by {@link #SCALE}
034     * and uses a seed of 123456789.
035     *
036     * @param xin x input; works well if between 0.0 and 1.0, but anything is accepted
037     * @param yin y input; works well if between 0.0 and 1.0, but anything is accepted
038     * @return noise from -1.0 to 1.0, inclusive
039     */
040    public static double noise(double xin, double yin) {
041        return ClassicNoise.instance.getNoiseWithSeed(xin * 0.11709966304863834, yin * 0.11709966304863834, 123456789);
042    }
043
044    /**
045     * Delegates to {@link ClassicNoise#getNoiseWithSeed(double, double, double, long)}; multiplies its inputs by
046     * {@link #SCALE} and uses a seed of 123456789.
047     *
048     * @param xin X input
049     * @param yin Y input
050     * @param zin Z input
051     * @return noise from -1.0 to 1.0, inclusive
052     */
053    public static double noise(double xin, double yin, double zin) {
054        return ClassicNoise.instance.getNoiseWithSeed(xin * 0.11709966304863834, yin * 0.11709966304863834, zin * 0.11709966304863834, 123456789);
055    }
056
057    /**
058     * Delegates to {@link ClassicNoise#getNoiseWithSeed(double, double, double, double, long)}; multiplies its inputs
059     * by {@link #SCALE} and uses a seed of 123456789.
060     *
061     * @param x X position
062     * @param y Y position
063     * @param z Z position
064     * @param w W position (fourth dimension)
065     * @return noise from -1.0 to 1.0, inclusive
066     */
067    public static double noise(double x, double y, double z, double w) {
068        return ClassicNoise.instance.getNoiseWithSeed(x * 0.11709966304863834, y * 0.11709966304863834, z * 0.11709966304863834, w * 0.11709966304863834, 123456789);
069    }
070}