Add num_to_range

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-04 12:43:57 +03:00
parent eb4d7c12fc
commit f3b84995e3

17
snippets/num_to_range.md Normal file
View File

@ -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
```