From a71efa41f09e878b5cfa68072e896df1a85bc51f Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 7 Dec 2022 02:23:06 -0500 Subject: cleaner organization of functions --- Assets/Scripts/MathFunctionLibrary.cs | 39 ++++++++++------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'Assets/Scripts/MathFunctionLibrary.cs') 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() - { - - } - */ + } -- cgit v1.2.3