git_music_visualize_3.py 389 B

123456789101112
  1. def translate(self, value, leftMin, leftMax, rightMin, rightMax):
  2. # Figure out how 'wide' each range is
  3. leftSpan = leftMax - leftMin
  4. rightSpan = rightMax - rightMin
  5. # Convert the left range into a 0-1 range (float)
  6. valueScaled = float(value - leftMin) / float(leftSpan)
  7. # Convert the 0-1 range into a value in the right range.
  8. return rightMin + (valueScaled * rightSpan)