Skip to content

Instantly share code, notes, and snippets.

@atika
Created March 10, 2016 10:10
Show Gist options
  • Save atika/f9ee912c8f701ea7cbf2 to your computer and use it in GitHub Desktop.
Save atika/f9ee912c8f701ea7cbf2 to your computer and use it in GitHub Desktop.
Remap/Convert a value from one range to another range (graph) in Swift
let high1 = 1000
let low1 = 200
let high2 = 250
let low2 = 10
let value = 200
let remapedValue = low2 + (value - low1) * (high2 - low2) / (high1 - low1)
print(remapedValue) //-> 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment