//Interpolation function and interpolated movement library by Dark Kitsune / Ran / Darkwalker

function linear(a,b,x) {
	return a + x * (b-a);
}

function smoothstep(a,b,x) {
	return a + x * x * (3 - 2 * x) * (b - a);
}

function smootherstep(a,b,x) {
	return a + x * x * x * (x * (x * 6 - 15) + 10) * (b - a);
}

function acceleration(a,b,x) {
	let v = x * x;
	return (b * v) + (a * (1 - v));
}

function deceleration(a,b,x) {
	let v = 1 - (1 - x) * (1 - x);
	return (b * v) + (a * (1 - v));
}

function overshoot(a,b,x,magnitude) {
	x = deceleration(0,1,x);
	return a + x * (b-a) * (1 + sin(x * 180) * magnitude);
}

task moveLinear(object,x,y,time) {
	let px = ObjRender_GetX(object);
	let py = ObjRender_GetY(object);
	let hash = IntToString(px)~IntToString(py);
	Obj_SetValue(object,"interhash",hash);
	let i = 0;
	while (!Obj_IsDeleted(object) && Obj_GetValue(object,"interhash") == hash && i < time) {
		i++;
		ObjRender_SetPosition(object,linear(px,x,i / time),linear(py,y,i / time), 0);
		yield;
	}
}

task moveOvershoot(object,x,y,time,magnitude) {
	let px = ObjRender_GetX(object);
	let py = ObjRender_GetY(object);
	let hash = IntToString(px)~IntToString(py);
	Obj_SetValue(object,"interhash",hash);
	let i = 0;
	while (!Obj_IsDeleted(object) && Obj_GetValue(object,"interhash") == hash && i < time) {
		i++;
		ObjRender_SetPosition(object,overshoot(px,x,i / time,magnitude),overshoot(py,y,i / time,magnitude), 0);
		yield;
	}
}

task moveSmooth(object,x,y,time) {
	let px = ObjRender_GetX(object);
	let py = ObjRender_GetY(object);
	let hash = IntToString(px)~IntToString(py);
	Obj_SetValue(object,"interhash",hash);
	let i = 0;
	while (!Obj_IsDeleted(object) && Obj_GetValue(object,"interhash") == hash && i < time) {
		i++;
		ObjRender_SetPosition(object,smoothstep(px,x,i / time),smoothstep(py,y,i / time), 0);
		yield;
	}
}

task moveSmoother(object,x,y,time) {
	let px = ObjRender_GetX(object);
	let py = ObjRender_GetY(object);
	let hash = IntToString(px)~IntToString(py);
	Obj_SetValue(object,"interhash",hash);
	let i = 0;
	while (!Obj_IsDeleted(object) && Obj_GetValue(object,"interhash") == hash && i < time) {
		i++;
		ObjRender_SetPosition(object,smootherstep(px,x,i / time),smootherstep(py,y,i / time), 0);
		yield;
	}
}

task moveAcceleration(object,x,y,time) {
	let px = ObjRender_GetX(object);
	let py = ObjRender_GetY(object);
	let hash = IntToString(px)~IntToString(py);
	Obj_SetValue(object,"interhash",hash);
	let i = 0;
	while (!Obj_IsDeleted(object) && Obj_GetValue(object,"interhash") == hash && i < time) {
		i++;
		ObjRender_SetPosition(object,acceleration(px,x,i / time),acceleration(py,y,i / time), 0);
		yield;
	}
}

task moveDeceleration(object,x,y,time) {
	let px = ObjRender_GetX(object);
	let py = ObjRender_GetY(object);
	let hash = IntToString(px)~IntToString(py);
	Obj_SetValue(object,"interhash",hash);
	let i = 0;
	while (!Obj_IsDeleted(object) && Obj_GetValue(object,"interhash") == hash && i < time) {
		i++;
		ObjRender_SetPosition(object,deceleration(px,x,i / time),deceleration(py,y,i / time), 0);
		yield;
	}
}