summaryrefslogtreecommitdiffhomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Graph.cs91
-rw-r--r--Assets/Scripts/MathFunctionLibrary.cs57
-rw-r--r--Assets/Scripts/MathFunctionLibrary.cs.meta11
3 files changed, 123 insertions, 36 deletions
diff --git a/Assets/Scripts/Graph.cs b/Assets/Scripts/Graph.cs
index 1486990..760d4c8 100644
--- a/Assets/Scripts/Graph.cs
+++ b/Assets/Scripts/Graph.cs
@@ -2,44 +2,63 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
+
public class Graph : MonoBehaviour
{
- [SerializeField]
- Transform pointPrefab;
-
- [SerializeField, Range(10, 100)]
- int resolution = 10;
-
- Transform[] points;
-
- void Awake() {
- points = new Transform[resolution];
- float step = 8f / points.Length;
- for(int i = 0; i < points.Length; i++) {
- Transform point = Instantiate(pointPrefab);
- points[i] = point;
- Vector3 position = pointPrefab.localPosition;
- point.SetParent(transform, false);
- position.x = (i + 0.5f) * step - 4f;
+ [SerializeField]
+ Transform pointPrefab;
+
+ [SerializeField, Range(10, 200)]
+ int resolution = 100;
+
+ [SerializeField, Range(0.1f, 2f)]
+ float size = 0.3f;
+
+ [SerializeField, Range(0, 2)]
+ int function = 1;
+
+ Transform[] points;
+
+ void Awake() {
+ points = new Transform[resolution];
+ float step = 8f / points.Length;
+ for(int i = 0; i < points.Length; i++) {
+ Transform point = Instantiate(pointPrefab);
+ points[i] = point;
+ Vector3 position = pointPrefab.localPosition;
+ point.SetParent(transform, false);
+ position.x = (i + 0.5f) * step - 4f;
point.localPosition = position;
- }
- }
-
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
+ point.localScale *= size;
+ }
+ }
+
+ // Start is called before the first frame update
+ void Start()
+ {
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
float time = Time.time;
- for(int i = 0; i < points.Length; i++) {
- Transform point = points[i];
- Vector3 position = point.localPosition;
- position.y = Mathf.Sin(Mathf.PI * (position.x + time));// * position.x * position.x;
- point.localPosition = position;
- }
- }
+ for(int i = 0; i < points.Length; i++) {
+ Transform point = points[i];
+ Vector3 position = point.localPosition;
+ if(function == 0)
+ {
+ position.y = MathFunctionLibrary.Wave(position.x, time);
+ }
+ else if(function == 1)
+ {
+ position.y = MathFunctionLibrary.MultiWave(position.x, time);
+ }
+ else if(function == 2)
+ {
+ position.y = MathFunctionLibrary.Ripple(position.x, time);
+ }
+ point.localPosition = position;
+ }
+ }
}
diff --git a/Assets/Scripts/MathFunctionLibrary.cs b/Assets/Scripts/MathFunctionLibrary.cs
new file mode 100644
index 0000000..d83b673
--- /dev/null
+++ b/Assets/Scripts/MathFunctionLibrary.cs
@@ -0,0 +1,57 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+using static UnityEngine.Mathf;
+
+public static class MathFunctionLibrary
+{
+ public delegate float Function(float x, float t);
+
+ public static float GetFunction(float x, float t)
+ {
+ if(index == 0)
+ {
+ return Wave;
+ }
+ else if(index == 1)
+ {
+ return MultiWave;
+ }
+ else //if(index == 2)
+ {
+ return Ripple;
+ }
+ }
+
+ public static float Wave(float x, float t)
+ {
+ return Sin(PI * (x + t));
+ }
+
+ public static float MultiWave(float x, float t)
+ {
+ float y = MathFunctionLibrary.Wave(x, t * 0.5f);
+ y += Sin(2f * PI * (x + t)) * 0.5f;
+ return y * (2f / 3f);
+ }
+
+ public static float Ripple(float x, float t) {
+ float d = Abs(x);
+ float y = Sin(PI * (4f * d - (2f * t)));
+ return y / (1f + 10f * d);
+ }
+ /*
+ // Start is called before the first frame update
+ void Start()
+ {
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+ */
+}
diff --git a/Assets/Scripts/MathFunctionLibrary.cs.meta b/Assets/Scripts/MathFunctionLibrary.cs.meta
new file mode 100644
index 0000000..e29eae2
--- /dev/null
+++ b/Assets/Scripts/MathFunctionLibrary.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: fe3850924a36450d5af9e18ad7bef1b6
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: