From a67ba8d52f04fc74d90f1885325f76cec04546f4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 28 Aug 2019 02:28:01 -0600 Subject: added arbitrary ramp shape powers to level_calc.py, to more easily hit specific values --- bin/level_calc.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'bin/level_calc.py') diff --git a/bin/level_calc.py b/bin/level_calc.py index f16f8ce..6f07621 100755 --- a/bin/level_calc.py +++ b/bin/level_calc.py @@ -14,7 +14,7 @@ def main(args): """ # Get parameters from the user questions_main = [ - (str, 'ramp_shape', 'cube', 'Ramp shape? [cube, square, fifth, seventh, ninth, log]'), + (str, 'ramp_shape', 'cube', 'Ramp shape? [cube, square, fifth, seventh, ninth, log, N.NN]'), (int, 'num_channels', 1, 'How many power channels?'), (int, 'num_levels', 4, 'How many total levels do you want?'), ] @@ -179,11 +179,19 @@ shapes = dict( ) def power(x): - return shapes[ramp_shape][0](x) + try: + factor = float(ramp_shape) + return math.pow(x, factor) + except ValueError: + return shapes[ramp_shape][0](x) def invpower(x): - return shapes[ramp_shape][1](x) + try: + factor = float(ramp_shape) + return math.pow(x, 1.0 / factor) + except ValueError: + return shapes[ramp_shape][1](x) def input_text(): -- cgit v1.2.3