show some love to hyper
This commit is contained in:
1 parent
6da13bac1c
commit
15c8fce77c
52 files changed
+4091
-2008
No files matched your search
@@ -0,0 +1,80 @@
|
||||
using Assets.WasapiAudio.Scripts.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpectrumMandlebrotBinder : MonoBehaviour {
|
||||
|
||||
[SerializeField] private Material mat;
|
||||
[SerializeField] private WasapiAudioSource source;
|
||||
[SerializeField] private Vector2 pos;
|
||||
[SerializeField] private float scale;
|
||||
[SerializeField] private float angle;
|
||||
[SerializeField] private float speed;
|
||||
|
||||
private Vector2 smoothPos;
|
||||
private float smoothScale;
|
||||
private float smoothAngle;
|
||||
|
||||
void Awake() {
|
||||
scale = 4.0f;
|
||||
}
|
||||
|
||||
private void HandleUserInput() {
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
|
||||
if (scroll > 0f) {
|
||||
scale *= 0.9f;
|
||||
} else if (scroll < 0f) {
|
||||
scale *= 1.1f;
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.Q)) {
|
||||
angle -= 0.01f;
|
||||
} else if (Input.GetKey(KeyCode.E)) {
|
||||
angle += 0.01f;
|
||||
}
|
||||
|
||||
Vector2 dir = new Vector2(0.01f * scale, 0);
|
||||
float s = Mathf.Sin(angle);
|
||||
float c = Mathf.Cos(angle);
|
||||
dir = new Vector2(dir.x * c, dir.x * s);
|
||||
if (Input.GetKey(KeyCode.A)) {
|
||||
pos -= dir;
|
||||
|
||||
} else if (Input.GetKey(KeyCode.D)) {
|
||||
pos += dir;
|
||||
}
|
||||
|
||||
dir = new Vector2(-dir.y, dir.x);
|
||||
if (Input.GetKey(KeyCode.W)) {
|
||||
pos += dir;
|
||||
} else if (Input.GetKey(KeyCode.S)) {
|
||||
pos -= dir;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateShader() {
|
||||
smoothPos = Vector2.Lerp(smoothPos, pos, 0.03f);
|
||||
smoothScale = Mathf.Lerp(smoothScale, scale, 0.03f);
|
||||
smoothAngle = Mathf.Lerp(smoothAngle, angle, 0.03f);
|
||||
float aspect = (float) Screen.width / Screen.height;
|
||||
float scaleX = smoothScale;
|
||||
float scaleY = smoothScale;
|
||||
|
||||
if (aspect > 1f) {
|
||||
scaleY /= aspect;
|
||||
} else {
|
||||
scaleX *= aspect;
|
||||
}
|
||||
mat.SetVector("_Area", new Vector4(smoothPos.x, smoothPos.y, scaleX, scaleY));
|
||||
mat.SetFloat("_Angle", smoothAngle);
|
||||
mat.SetFloat("_Speed", speed);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
var spectrumData = source.GetSpectrumData();
|
||||
// speed = spectrumData[1];
|
||||
mat.SetFloat("_Movement", Mathf.PI * 2 * spectrumData[0]);
|
||||
mat.SetFloat("_EscapeRadius", Mathf.Clamp(50.0f * spectrumData[0], 2.1f, 50.0f));
|
||||
UpdateShader();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user