/// <summary> /// 1次元パーリンノイズを生成する /// </summary> /// <param name="x">x座標</param> /// <returns>波形の高さ</returns> public float Noise(float x) { // 整数部分と小数部分に分ける float fx = x % 1; int ix = (int)x; float wave = PerlinNoise1D.Wavelet(fx, Random.GetSmallRandom(unchecked (this.seed + ix))); float nextWave = PerlinNoise1D.Wavelet(fx - 1f, Random.GetSmallRandom(unchecked (this.seed + ix + 1))); return(Mathf.Lerp(wave, nextWave, fx)); }
// Use this for initialization /// <summary> /// Starts this instance. /// </summary> private void Start() { var perlin = new TGM.Lib.Math.PerlinNoise1D(this.seed); var line = this.GetOrAddComponent <LineRenderer>(); line.positionCount = this.maxStep; for (int i = 0; i < this.maxStep; i++) { float x = this.accuracy * (float)i; float value = perlin.Noise(x) * this.amplitude; line.SetPosition(i, new Vector3(x * this.width, 0f, value)); } }