fantas.curve¶
提供曲线相关的类和预定义曲线。
- class fantas.curve.CurveBase¶
曲线抽象基类。
通过曲线求值的方式是直接调用曲线对象,传入因变量, 因此子类需要实现 __call__ 方法来定义曲线的具体形状。
- class fantas.curve.FormulaCurve(formula: str)¶
使用数学公式定义的曲线。
提示
公式曲线在求值时会自动使用缓存,因此不用担心太复杂的求值公式会导致性能问题。
你可以提前空跑一些可能用到的 x 值来预热缓存。
- formula: str¶
用于计算 y 值的数学公式,变量为 x。以及 float 和 int 类型转换函数。 其他数学函数需要通过 math 模块调用,例如 math.sqrt(x)。
- fantas.curve.CURVE_LINEAR(x)¶
线性曲线,y = x
- 参数:
x (float) -- 输入的 x 值。
- 返回:
对应的 y 值。
- 返回类型:
float
- fantas.curve.CURVE_FASTER(x)¶
渐快曲线,y = x^2
- 参数:
x (float) -- 输入的 x 值。
- 返回:
对应的 y 值。
- 返回类型:
float
- fantas.curve.CURVE_SLOWER(x)¶
渐慢曲线,y = 2x - x^2
- 参数:
x (float) -- 输入的 x 值。
- 返回:
对应的 y 值。
- 返回类型:
float
- fantas.curve.CURVE_SMOOTH: FormulaCurve = FormulaCurve(formula='(1-cos(pi*x))/2')¶
平滑曲线,y = (1 - cos(pi * x)) / 2
- 参数:
x (float) -- 输入的 x 值。
- 返回:
对应的 y 值。
- 返回类型:
float