private double Generate(double x) { int X = ((int)Math.Floor(x)) & 0xff; x -= Math.Floor(x); double u = PerlinUtil.Fade(x); return(PerlinUtil.Lerp(u, PerlinUtil.Grad(perm[X], x), PerlinUtil.Grad(perm[X + 1], x - 1)) * 2.0d); }
private double Generate(double x, double y) { int X = ((int)Math.Floor(x)) & 0xff; int Y = ((int)Math.Floor(y)) & 0xff; x -= Math.Floor(x); y -= Math.Floor(y); double u = PerlinUtil.Fade(x); double v = PerlinUtil.Fade(y); int A = (perm[X] + Y) & 0xff; int B = (perm[X + 1] + Y) & 0xff; return(PerlinUtil.Lerp(v, PerlinUtil.Lerp(u, PerlinUtil.Grad(perm[A], x, y), PerlinUtil.Grad(perm[B], x - 1.0d, y)), PerlinUtil.Lerp(u, PerlinUtil.Grad(perm[A + 1], x, y - 1.0d), PerlinUtil.Grad(perm[B + 1], x - 1.0d, y - 1.0d)) )); }
void Update() { if (Time.timeScale > 0f) { Vector3 position = zero; if (kick != Vector2.zero) { position += (Vector3)(kick * kickScale); kick = Vector2.MoveTowards(kick, Vector2.zero, kickFalloff * Time.deltaTime); } if (intensity != 0f) { t += Time.deltaTime * shakeSpeed; position += (Vector3)(intensity * intensityScale * PerlinUtil.Variance2D(t)); intensity = Mathf.MoveTowards(intensity, 0f, intensityFalloff * Time.deltaTime); } transform.localPosition = position; } }
// constructor public SimplexNoise(int seed = 0) { Interlocked.Exchange(ref this.seed, seed); Interlocked.Exchange(ref perm, PerlinUtil.GetPerm(seed)); }