-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremap.py
More file actions
23 lines (18 loc) · 798 Bytes
/
remap.py
File metadata and controls
23 lines (18 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import math
def remap_range(value, left_min, left_max, right_min, right_max):
# log addition
log_left_min = math.log(left_min + 1e-5)
log_left_max = math.log(left_max)
log_value = math.log(value+1e-5)
# this remaps a value from original (left) range to new (right) range
# Figure out how 'wide' each range is
left_span = log_left_max - log_left_min
right_span = right_max - right_min
# Convert the left range into a 0-1 range (int)
valueScaled = float(log_value - log_left_min) / float(left_span)
# Convert the 0-1 range into a value in the right range.
return float(right_min + (valueScaled * right_span))
print(remap_range(0, 0, 65535, 0, 100))
print(remap_range(5000, 0, 65535, 0, 100))
print(remap_range(30000, 0, 65535, 0, 100))
print(remap_range(65535, 0, 65535, 0, 100))