Copyright © ZOZO Technologies, Inc. All Right Reserved.
var currentPointY: CGFloat = 0.0
override func touchesMoved(_ touches: Set, with event: UIEvent?) {
guard let touch = touches.first else { return }
let diff = touch.previousLocation(in: view).y - touch.location(in: view).y
currentPointY += diff
let max = 60
let temperature = Int(currentPointY / (view.frame.height / CGFloat(max)))
let ratio = (temperature * 100 / max)
let startColor = UIColor(red: 79/255, green: 140/255, blue: 248/255, alpha: 1.0)
let endColor = UIColor(red: 218/255, green: 20/255, blue: 40/255, alpha: 1.0)
// R(X) = (Rb - Ra) * X/100 + Ra
let r = (endColor.red - startColor.red) * CGFloat(ratio) / 100 + startColor.red
let g = (endColor.green - startColor.green) * CGFloat(ratio) / 100 + startColor.green
let b = (endColor.blue - startColor.blue) * CGFloat(ratio) / 100 + startColor.blue
view.backgroundColor = UIColor(red: r, green: g, blue: b, alpha: 1.0)
}