// interpolating float functions class FloatFunction { 0.0 => float default; fun float evaluate(float arg) { return default; } } // always return an uniform value class Uniform extends FloatFunction { float value; fun float evaluate(float arg) { return value; } } // always return the argument class Identity extends FloatFunction { fun float evaluate(float arg) { return arg; } } // return the inverse of the argument class Inverse extends FloatFunction { fun float evaluate(float arg) { return (1.0 - arg); } } class Negative extends FloatFunction { fun float evaluate(float arg) { return (-arg); } } // trig functions, expects arg in radians // nest a function to interpolate between 0.0 and 1.0 and radians class Sin extends FloatFunction { fun float evaluate(float arg) { return Math.sin(arg); } } class Cos extends FloatFunction { fun float evaluate(float arg) { return Math.cos(arg); } } class Tan extends FloatFunction { fun float evaluate(float arg) { return Math.tan(arg); } } class Asin extends FloatFunction { fun float evaluate(float arg) { return Math.asin(arg); } } class Acos extends FloatFunction { fun float evaluate(float arg) { return Math.acos(arg); } } class Atan extends FloatFunction { fun float evaluate(float arg) { return Math.atan(arg); } } class Sinh extends FloatFunction { fun float evaluate(float arg) { return Math.sinh(arg); } } class Cosh extends FloatFunction { fun float evaluate(float arg) { return Math.cosh(arg); } } class Tanh extends FloatFunction { fun float evaluate(float arg) { return Math.tanh(arg); } } // other math functions class Sqrt extends FloatFunction { fun float evaluate(float arg) { return Math.sqrt(arg); } } class Exp extends FloatFunction { fun float evaluate(float arg) { return Math.exp(arg); } } class Log extends FloatFunction { fun float evaluate(float arg) { return Math.log(arg); } } class Log2 extends FloatFunction { fun float evaluate(float arg) { return Math.log2(arg); } } class Log10 extends FloatFunction { fun float evaluate(float arg) { return Math.log10(arg); } } class Floor extends FloatFunction { fun float evaluate(float arg) { return Math.floor(arg); } } class Ceil extends FloatFunction { fun float evaluate(float arg) { return Math.ceil(arg); } } class Round extends FloatFunction { fun float evaluate(float arg) { return Math.round(arg); } } class Trunc extends FloatFunction { fun float evaluate(float arg) { return Math.trunc(arg); } } class Interpolation extends FloatFunction { 0.0 => float min; 1.0 => float max; } class LinearIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * arg); } } class LinearOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * arg); } } class Random extends Interpolation { fun float evaluate(float arg) { return Std.rand2f(min, max); } } // next two more useful with nested interpolation class RandomThreshold extends Interpolation { fun float evaluate(float arg) { return Std.rand2f(min, arg); } } class RandomFloor extends Interpolation { fun float evaluate(float arg) { return Std.rand2f(arg, max); } } class QuadraticIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * Math.pow(arg, 2.0)); } } class QuadraticOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * Math.pow(arg, 2.0)); } } class QuadraticInOut extends Interpolation { fun float evaluate(float arg) { if (arg < 0.5) { return min + (Std.fabs(max - min) * Math.pow(arg, 2.0)); } else { return max - (Std.fabs(max - min) * Math.pow(1.0 - arg, 2.0)); } } } class CubicIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * Math.pow(arg, 3.0)); } } class CubicOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * Math.pow(arg, 3.0)); } } class CubicInOut extends Interpolation { fun float evaluate(float arg) { if (arg < 0.5) { return min + (Std.fabs(max - min) * Math.pow(arg, 3.0)); } else { return max - (Std.fabs(max - min) * Math.pow(1.0 - arg, 3.0)); } } } class QuarticIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * Math.pow(arg, 4.0)); } } class QuarticOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * Math.pow(arg, 4.0)); } } class QuarticInOut extends Interpolation { fun float evaluate(float arg) { if (arg < 0.5) { return min + (Std.fabs(max - min) * Math.pow(arg, 4.0)); } else { return max - (Std.fabs(max - min) * Math.pow(1.0 - arg, 4.0)); } } } class QuinticIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * Math.pow(arg, 5.0)); } } class QuinticOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * Math.pow(arg, 5.0)); } } class QuinticInOut extends Interpolation { fun float evaluate(float arg) { if (arg < 0.5) { return min + ((Std.fabs(max - min)/2.0) * Math.pow(2.0 * arg, 5.0)); } else { return max - ((Std.fabs(max - min)/2.0) * Math.pow(1.0 - (arg/2.0), 5.0)); } } } /* class SinusoidalIn extends Interpolation { fun float evaluate(float arg) { } } class SinusoidalOut extends Interpolation { fun float evaluate(float arg) { } } class SinusoidalInOut extends Interpolation { fun float evaluate(float arg) { } } */ class ExponentialIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * Math.pow(2.0, 10 * (arg - 1.0))); } } class ExponentialOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * Math.pow(2.0, 10 * (arg - 1.0))); } } /* class ExponentialInOut extends Interpolation { fun float evaluate(float arg) { } } */ class CircularIn extends Interpolation { fun float evaluate(float arg) { return min + (Std.fabs(max - min) * (1 - Math.sqrt(1.0 - (arg * arg)))); } } class CircularOut extends Interpolation { fun float evaluate(float arg) { return max - (Std.fabs(max - min) * (1 - Math.sqrt(1.0 - (arg * arg)))); } } /* class CircularInOut extends Interpolation { fun float evaluate(float arg) { } } */ // composite of two functions, g(h(arg)); class CompositeFloatFunction extends FloatFunction { FloatFunction g; FloatFunction h; fun float evaluate(float arg) { return g.evaluate(h.evaluate(arg)); } } class FloatFunctions { fun static FloatFunction chain(FloatFunction g, FloatFunction h) { CompositeFloatFunction composite; g @=> composite.g; h @=> composite.h; return composite; } fun static FloatFunction identity(FloatFunction fn) { Identity identity; return chain(identity, fn); } fun static FloatFunction inverse(FloatFunction fn) { Inverse inverse; return chain(inverse, fn); } fun static FloatFunction negative(FloatFunction fn) { Negative negative; return chain(negative, fn); } fun static FloatFunction sin(FloatFunction fn) { Sin sin; return chain(sin, fn); } fun static FloatFunction cos(FloatFunction fn) { Cos cos; return chain(cos, fn); } fun static FloatFunction tan(FloatFunction fn) { Tan tan; return chain(tan, fn); } fun static FloatFunction asin(FloatFunction fn) { Asin asin; return chain(asin, fn); } fun static FloatFunction acos(FloatFunction fn) { Acos acos; return chain(acos, fn); } fun static FloatFunction atan(FloatFunction fn) { Atan atan; return chain(atan, fn); } fun static FloatFunction sinh(FloatFunction fn) { Sinh sinh; return chain(sinh, fn); } fun static FloatFunction cosh(FloatFunction fn) { Cosh cosh; return chain(cosh, fn); } fun static FloatFunction tanh(FloatFunction fn) { Tanh tanh; return chain(tanh, fn); } fun static FloatFunction sqrt(FloatFunction fn) { Sqrt sqrt; return chain(sqrt, fn); } fun static FloatFunction exp(FloatFunction fn) { Exp exp; return chain(exp, fn); } fun static FloatFunction log(FloatFunction fn) { Log log; return chain(log, fn); } fun static FloatFunction log2(FloatFunction fn) { Log2 log2; return chain(log2, fn); } fun static FloatFunction log10(FloatFunction fn) { Log10 log10; return chain(log10, fn); } fun static FloatFunction floor(FloatFunction fn) { Floor floor; return chain(floor, fn); } fun static FloatFunction ceil(FloatFunction fn) { Ceil ceil; return chain(ceil, fn); } fun static FloatFunction round(FloatFunction fn) { Round round; return chain(round, fn); } fun static FloatFunction trunc(FloatFunction fn) { Trunc trunc; return chain(trunc, fn); } } Uniform uniform; Inverse inverse; CompositeFloatFunction composite; inverse @=> composite.g; 0.75 => uniform.value; uniform @=> composite.h; FloatFunctions.inverse(uniform) @=> FloatFunction composite2; FloatFunctions f; f.inverse(uniform) @=> FloatFunction composite3; f.chain(inverse, uniform) @=> FloatFunction composite4; <<>>; <<>>; <<>>; <<>>; <<<"ok">>>;