Skip to content

Instantly share code, notes, and snippets.

@vladdeSV
Last active March 27, 2022 21:08
Show Gist options
  • Save vladdeSV/1f0b61f94fbcbcdd89a123b042211b08 to your computer and use it in GitHub Desktop.
Save vladdeSV/1f0b61f94fbcbcdd89a123b042211b08 to your computer and use it in GitHub Desktop.
My commonly used math-related helper functions in Game Maker Language
function map_range(a, b, c, d, value) {
return (value - a) / (b - a) * (d - c) + c
}
function normalize_arctan2_angle(angle) {
return (angle > 0) ? angle : angle + 2 * pi
}
function sin01(x) {
return 0.5 * (sin(x) + 1)
}
function cos01(x) {
return 0.5 * (cos(x) + 1)
}
function degrees_to_radians(degrees) {
return degrees / 180 * pi
}
function radians_to_degrees(radians) {
return radians * 180 / pi
}
function lerp2(a, b, t, threshold = 0.001) {
if (a == b) {
return b
}
if (abs(a - b) < threshold) {
return b
}
return lerp(a, b, t)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment