craftyjs.github.com

Crafty.math

Static functions.

Back to top

Crafty.math.abs

public this Crafty.math.abs(Number n)

n
Some value.

Returns

Absolute value.

Returns the absolute value.

Back to top

Crafty.math.amountOf

public Number Crafty.math.amountOf(Number checkValue, Number minValue, Number maxValue)

checkValue
Value that should checked with minimum and maximum.
minValue
Minimum value to check.
maxValue
Maximum value to check.

Returns

Amount of checkValue compared to minValue and maxValue.

Returns the amount of how much a checkValue is more like minValue (=0) or more like maxValue (=1)

Back to top
Converts angle from degree to radian.
angleInDeg
The angle in degree.

Returns

The angle in radian.

Back to top
Converts angle from degree to radian.
angleInDeg
The angle in degree.

Returns

The angle in radian.

Back to top

Crafty.math.distance

public Number Crafty.math.distance(Number x1, Number y1, Number x2, Number y2)

x1
First x coordinate.
y1
First y coordinate.
x2
Second x coordinate.
y2
Second y coordinate.

Returns

The distance between the two points.

Distance between two points.

Back to top

Crafty.math.lerp

public Number Crafty.math.lerp(Number value1, Number value2, Number amount)

value1
One value.
value2
Another value.
amount
Amount of value2 to value1.

Returns

Linear interpolated value.

Linear interpolation. Passing amount with a value of 0 will cause value1 to be returned, a value of 1 will cause value2 to be returned.

Back to top

Crafty.math.negate

public Number Crafty.math.negate(Number percent)

percent
If you pass 1 a -1 will be returned. If you pass 0 a 1 will be returned.

Returns

1 or -1.

Returnes "randomly" -1.

Back to top

Crafty.math.radToDeg

public Number Crafty.math.radToDeg(Number angle)

angleInRad
The angle in radian.

Returns

The angle in degree.

Converts angle from radian to degree.

Back to top

Crafty.math.randomElementOfArray

public Object Crafty.math.randomElementOfArray(Array array)

array
A specific array.

Returns

A random element of a specific array.

Returns a random element of a specific array.

Back to top

Crafty.math.randomInt

public Number Crafty.math.randomInt(Number start, Number end)

start
Smallest int value that can be returned.
end
Biggest int value that can be returned.

Returns

A random int.

Returns a random int in within a specific range.

Back to top

Crafty.math.randomNumber

public Number Crafty.math.randomInt(Number start, Number end)

start
Smallest number value that can be returned.
end
Biggest number value that can be returned.

Returns

A random number.

Returns a random number in within a specific range.

Back to top

Crafty.math.squaredDistance

public Number Crafty.math.squaredDistance(Number x1, Number y1, Number x2, Number y2)

x1
First x coordinate.
y1
First y coordinate.
x2
Second x coordinate.
y2
Second y coordinate.

Returns

The squared distance between the two points.

Squared distance between two points.

Back to top

Crafty.math.withinRange

public Boolean Crafty.math.withinRange(Number value, Number min, Number max)

value
The specific value.
min
Minimum value.
max
Maximum value.

Returns

Returns true if value is within a specific range.

Check if a value is within a specific range.