May 28, 2009

Weighted Average

A simple script that allows you to take the average of two numbers... with a weight.

return (argument1-argument0)*argument2+argument0


Argument zero is the "small number", this should be considered your minimum, and is the result when you weight it to 0.
Argument one is the "big number", the result when you set the weight to 1, and also your "maximum".
Argument two is your weighted value, a percentage. Keep in mind that to calculate percents (Sorry if you already know this), the calculation is as follows: 100%/100=1, 50%/100=.5, 102.87%/100=1.0287. Simply push the decimal over. .5 is the average of the two numbers. (a+b)/2 It comes up with the number exactly between the two numbers.

Use this code to come up with different numbers between, based on a weight.
Uses I have discovered:

Graphics: A nice way to place a point between two points somewhere, I use it to place a point representing a stat, so if the best str you can have at level 1337 is 42, and you have 31 str, it would place the point closer to the 42 than to the 0.
Circles: Smooth turning for objects is possible with this code, by using the argument2 value as the dynamic, or changing, value. Smooth turning is easily accomplished, and looks good.
The obvious: You can use this to average.
Stats: If you want a weighted, maybe even linear, stat system, this is the one for you.