You are not logged in.
Pages: 1
/*
** Usage:
** v = mergefromto(from,to,value);
**
** Arguments:
** from value to return if value is 0
** to value to return if value is 1
** value a value from 0 to 1
**
** Returns:
** v like merge_color, it returns "from" when value is 0, "to" when value is 1 an appropriate in between value when value is between 0 and 1
**
** Notes:
** ret = mergefromto(value if 0, value if 1, 0 to 1)
** calculating percent
** percent = mergefromto(0,100,curval/maxval);
** calculating some odd range
** centerXoffset = mergefromto(-320,320,mouse_x/screen_width);
**
** GMLscripts.com
*/
return(argument0+(argument1-argument0)*argument2)
I can't find a better name for it
Offline
[ MISSING ]
Offline
hey, awesome script
I have the same exact function, but I like calling it merge_number() instead
I've been using it for pretty much everything since I figured it out a few years ago
Also useful in this area of number merging are these scripts:
unmerge_number(merged value,n1,n2), the reverse of merge number. for example, merge_number(n1,n2,unmerge_number(x,n1,n2)) will always return x
// unmerge_number(merged number, n1, n2)
if argument2-argument1!=0
return ((argument0-argument1)/(argument2-argument1))
else return 0
and
merge_direction(dir1,dir2,merge), which works the same as merge number but will merge two directions, even if they are outside of 360 degrees (however it will not always return a direction between 0 and 360)
//merge_direction(num1,num2,merging value)
while argument0>360 argument0-=360
while argument1>360 argument1-=360
while argument0<0 argument0+=360
while argument1<0 argument1+=360
if argument0>=180 {if argument1<180 and argument1<argument0-180 argument1+=360}
else if argument0<180 {if argument1>=180 and argument1>argument0+180 argument1-=360}
return merge_number(argument0,argument1,argument2)
Offline
Pages: 1