using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VisiMath.Fractals
{
    public class PerlinTerrain : HeightMap
    {
        protected PerlinNoise Noise;
        protected int Octaves;
        protected float Persistence;

        
        public override float this[float indexX, float indexY]
        {
            get
            {
                return 64*Noise.GetNoise(0.0001f * indexX / _width, 0.0001f * indexY / _height, Persistence, Octaves) +
                    16*Noise.GetNoise(0.01f * indexX / _width, 0.01f * indexY / _height, Persistence, Octaves) 
                    + 2*Noise.GetNoise(indexX/_width, indexY/_height, Persistence, Octaves);
            }
            set
            {
                return;
            }
        }


        public PerlinTerrain(Random rgn, int xsize, int ysize) : this(rgn)
        {
            _width = xsize;
            _height = ysize;
        }

        public PerlinTerrain(int xsize, int ysize)
            : this(null, xsize, ysize)
        {
        }

        public PerlinTerrain(Random rgn = null, int octaves = 6, float persistence = 1.0f)
        {
            if (_width == 0) _width = 100;
            if (_height == 0) _height = 100;
            if (rgn == null)
                rgn = new Random();

            Octaves = octaves;
            Persistence = persistence;

            Noise = new PerlinNoise(rgn, 256);
        }

    }
}
