Skip to content

Instantly share code, notes, and snippets.

@Geri-Borbas
Last active January 11, 2021 20:40
Show Gist options
  • Save Geri-Borbas/e212e933f0c4efaff6ff84354aea77fc to your computer and use it in GitHub Desktop.
Save Geri-Borbas/e212e933f0c4efaff6ff84354aea77fc to your computer and use it in GitHub Desktop.
Simplified/normalized CGFloat easing algorithms. See https://github.com/Geri-Borbas/Unity.Library.eppz_easing for more.
extension CGFloat {
var linear: CGFloat {
self
}
var easeIn_1: CGFloat {
pow(self, 2)
}
var easeIn_2: CGFloat {
pow(self, 3)
}
var easeIn_3: CGFloat {
pow(self, 8)
}
var easeOut_1: CGFloat {
1.0 - pow(1.0 - self, 2)
}
var easeOut_2: CGFloat {
1.0 - pow(1.0 - self, 4)
}
var easeOut_3: CGFloat {
1.0 - pow(1.0 - self, 8)
}
var easeInOut_1: CGFloat {
(self < 0.5)
? 2.0 * pow(self, 2)
: -2.0 * pow(self, 2) + 4.0 * self - 1.0;
}
var easeInOut_2: CGFloat {
(self < 0.5)
? 4.0 * pow(self, 3)
: 4.0 * pow(self, 3) - 12.0 * pow(self, 2) + 12.0 * self - 3.0;
}
var easeInOut_3: CGFloat {
(self < 0.5)
? 128.0 * pow(self, 8)
: 0.5 + (1.0 - pow((1.0 - self) * 2.0, 8)) / 2.0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment