summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Assets/Scripts/Graph.cs14
-rw-r--r--Assets/Scripts/MathFunctionLibrary.cs39
2 files changed, 13 insertions, 40 deletions
diff --git a/Assets/Scripts/Graph.cs b/Assets/Scripts/Graph.cs
index 760d4c8..1b4ad63 100644
--- a/Assets/Scripts/Graph.cs
+++ b/Assets/Scripts/Graph.cs
@@ -42,22 +42,12 @@ public class Graph : MonoBehaviour
// Update is called once per frame
void Update()
{
+ MathFunctionLibrary.Function visual_function = MathFunctionLibrary.GetFunction(function);
float time = Time.time;
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);
- }
+ position.y = visual_function(position.x, time);
point.localPosition = position;
}
}
diff --git a/Assets/Scripts/MathFunctionLibrary.cs b/Assets/Scripts/MathFunctionLibrary.cs
index d83b673..1169eca 100644
--- a/Assets/Scripts/MathFunctionLibrary.cs
+++ b/Assets/Scripts/MathFunctionLibrary.cs
@@ -8,20 +8,15 @@ public static class MathFunctionLibrary
{
public delegate float Function(float x, float t);
- public static float GetFunction(float x, float t)
+ static Function[] functions = {
+ Wave,
+ MultiWave,
+ Ripple
+ };
+
+ public static Function GetFunction(int index)
{
- if(index == 0)
- {
- return Wave;
- }
- else if(index == 1)
- {
- return MultiWave;
- }
- else //if(index == 2)
- {
- return Ripple;
- }
+ return functions[index];
}
public static float Wave(float x, float t)
@@ -31,27 +26,15 @@ public static class MathFunctionLibrary
public static float MultiWave(float x, float t)
{
- float y = MathFunctionLibrary.Wave(x, t * 0.5f);
+ float y = 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) {
+ 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()
- {
-
- }
- */
+
}