From f3b84995e3221da8af16a71e4fd516acdff2959c Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 4 Oct 2020 12:43:57 +0300 Subject: [PATCH] Add num_to_range --- snippets/num_to_range.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/num_to_range.md diff --git a/snippets/num_to_range.md b/snippets/num_to_range.md new file mode 100644 index 000000000..05c1dcbd8 --- /dev/null +++ b/snippets/num_to_range.md @@ -0,0 +1,17 @@ +--- +title: num_to_range +tags: math,beginner +--- + +Maps a number from one range to another range. + +- Returns `num` mapped between `outMin`-`outMax` from `inMin`-`inMax`. + +```py +def num_to_range(num, inMin, inMax, outMin, outMax): + return outMin + ((float(num - inMin) / float((inMax - inMin))) * (outMax - outMin)) +``` + +```py +num_to_range(5, 0, 10, 0, 100) # 50.0 +```