scale function

double scale(
  1. num value,
  2. num min,
  3. num max,
  4. num newMin,
  5. num newMax,
)

Scales a value from one range to another.

This function takes a value within a specified range and scales it to a new range.

param value The value to be scaled. param min The minimum value of the original range. param max The maximum value of the original range. param newMin The minimum value of the new range. param newMax The maximum value of the new range. returns The scaled value within the new range.

Implementation

double scale(num value, num min, num max, num newMin, num newMax) {
  return (value - min) * (newMax - newMin) / (max - min) + newMin;
}