public Color Mutate(Color c) { float h, s, v; Color.RGBToHSV(c, out h, out s, out v); h = Mathfx.Frac(h + Hue); s = Mathf.Clamp01(s + Sat); v = Mathf.Clamp01(v + Val); return(Color.HSVToRGB(h, s, v).WithAlpha(c.a)); }
public void Listen(SmartValue value) { var strength = 0f; _timer += Time.deltaTime; var frac = Mathf.Clamp01(Mathfx.Frac((_timer / 60) * BPM)); strength = PulseShape.Evaluate(frac); value.AddValue(strength); }
public void AutoFillRandom() { Templates.Clear(); for (var i = 0; i < 60; ++i) { var rootHue = Random.value; Templates.Add(new Template() { Color0 = Color.HSVToRGB(rootHue, Random.Range(.7f, 1f), Random.Range(.9f, 1f)), Color1 = Color.HSVToRGB(Mathfx.Frac(rootHue + Random.Range(1 / 6f, 1 / 4f)), Random.Range(.7f, 1f), Random.Range(.9f, 1f)), Color2 = Color.HSVToRGB(Mathfx.Frac(rootHue - Random.Range(1 / 6f, 1 / 4f)), Random.Range(.7f, 1f), Random.Range(.7f, 1f)), }); } }
TransformState GetTransformState(float t) { float totalTime = TotalTime; float nt = t / totalTime; float curveTime = nt * CurveCount; //Circular float degRad = curveTime * Mathf.PI * 2; Vector3 circleAngle = new Vector3(Mathf.Sin(degRad), Mathf.Cos(degRad), 0); var rotation = -Quaternion.LookRotation(circleAngle.normalized, Vector3.forward).eulerAngles; // Poly if (Polygonal) { float fIndex = Mathfx.Frac(curveTime) * (_polygonPoints.Count - 1); int lowIndex = Mathf.FloorToInt(fIndex); int highIndex = Mathf.CeilToInt(fIndex); if (highIndex >= _polygonPoints.Count) { highIndex = 0; } if (lowIndex < 0 || lowIndex >= _polygonPoints.Count) { lowIndex = 0; } float frac = Mathfx.Frac(fIndex); Vector2 point = Vector2.Lerp(_polygonPoints[lowIndex], _polygonPoints[highIndex], frac); circleAngle = point; //rotation = Vector3.Cross(_polygonPoints[lowIndex] - _polygonPoints[highIndex], _polygonPoints[lowIndex]); } var flatTarget = Vector2.Lerp(Vector2.zero, PlaneTarget, PlaneTargetInterpolation.Evaluate(nt)); var z = Mathf.Lerp(0, Distance, DistanceTargetInterpolation.Evaluate(nt)); var targetPos = new Vector3(flatTarget.x, flatTarget.y, z); var circlePos = circleAngle * RadiusOverTime.Evaluate(nt) * Radius; var finalPosition = targetPos + circlePos; var scale = Scale * ScaleOverTime.Evaluate(nt); return(new TransformState(finalPosition, rotation, scale)); }
Vector3 GetPhase(int number) { var phase = _phase; if (number == 0) { //phase = Phases.Count -_phase; } var lower = Mathf.FloorToInt(phase); var upper = Mathf.CeilToInt(phase); if (upper == Phases.Count) { upper = 0; } var f = Mathfx.Frac(phase); var lowerPhase = Phases[lower]; var upperPhase = Phases[upper]; return(Vector3.Lerp(lowerPhase.Phase1, upperPhase.Phase1, f)); }
void Update() { if (_block == null) { _block = new MaterialPropertyBlock(); } var ms = MusicManager.MusicState; var w = ms.Wavelength; _rotationHistory.Add(transform.rotation); while (_rotationHistory.Count > w.Length) { _rotationHistory.RemoveAt(0); } for (var i = 0; i < w.Length; i += Step) { var percent = i / (float)w.Length; if (percent < Range.x) { continue; } var f = w[i]; var r = transform.rotation * Quaternion.Euler(MeshRotation); if (i < _rotationHistory.Count) { r = _rotationHistory[i]; } var s = transform.localToWorldMatrix.MultiplyPoint3x4(new Vector3((i + f) * Scale.x, (i + f) * Scale.y, (i + f) * Scale.z)); var trs = Matrix4x4.TRS(transform.position, r, s); _block.SetFloat("_U", i / (float)w.Length); _block.SetFloat("_Strength", f); Random.InitState(i); _block.SetColor("_Color", Color.Evaluate(Mathfx.Frac((i / ColorTiling)))); Graphics.DrawMesh(Mesh, trs, Material, 0, null, 0, _block); } }