LittleJS Utility Classes and Functions
- General purpose math library
- Vector2 - fast, simple, easy 2D vector class
- Color - holds a rgba color with some math functions
- Timer - tracks time automatically
- Source
Members
(static, constant) PI :Number
A shortcut to get Math.PI
- Number
- Default Value
- Math.PI
- Source
Methods
(static) abs(value) → {Number}
Returns absoulte value of value passed in
Name | Type | Description |
---|---|---|
value | Number |
- Source
- Type:
- Number
(static) clamp(value, minopt, maxopt) → {Number}
Clamps the value beween max and min
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value | Number | |||
min | Number | <optional> | 0 | |
max | Number | <optional> | 1 |
- Source
- Type:
- Number
(static) formatTime(t) → {String}
Formats seconds to mm:ss style for display purposes
Name | Type | Description |
---|---|---|
t | Number | time in seconds |
- Source
- Type:
- String
(static) hsl(hopt, sopt, lopt, aopt) → {Color}
Create a color object with HSLA values
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
h | Number | <optional> | 0 | |
s | Number | <optional> | 0 | |
l | Number | <optional> | 1 | |
a | Number | <optional> | 1 |
- Source
- Type:
- Color
(static) isOverlapping(pointA, sizeA, pointB, sizeBopt) → {Boolean}
Returns true if two axis aligned bounding boxes are overlapping
Name | Type | Attributes | Description |
---|---|---|---|
pointA | Vector2 | Center of box A | |
sizeA | Vector2 | Size of box A | |
pointB | Vector2 | Center of box B | |
sizeB | Vector2 | <optional> | Size of box B |
- Source
- True if overlapping
- Type:
- Boolean
(static) isVector2(vector) → {Boolean}
Check if object is a valid Vector2
Name | Type | Description |
---|---|---|
vector | Vector2 |
- Source
- Type:
- Boolean
(static) lerp(percent, minopt, maxopt) → {Number}
Linearly interpolates the percent value between max and min
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
percent | Number | |||
min | Number | <optional> | 0 | |
max | Number | <optional> | 1 |
- Source
- Type:
- Number
(static) max(valueA, valueB) → {Number}
Returns highest of two values passed in
Name | Type | Description |
---|---|---|
valueA | Number | |
valueB | Number |
- Source
- Type:
- Number
(static) min(valueA, valueB) → {Number}
Returns lowest of two values passed in
Name | Type | Description |
---|---|---|
valueA | Number | |
valueB | Number |
- Source
- Type:
- Number
(static) mod(dividend, divisoropt) → {Number}
Returns first parm modulo the second param, but adjusted so negative numbers work as expected
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dividend | Number | |||
divisor | Number | <optional> | 1 |
- Source
- Type:
- Number
(static) nearestPowerOfTwo(value) → {Number}
Returns the nearest power of two not less then the value
Name | Type | Description |
---|---|---|
value | Number |
- Source
- Type:
- Number
(static) percent(value, minopt, maxopt) → {Number}
Returns what percentage the value is between max and min
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value | Number | |||
min | Number | <optional> | 0 | |
max | Number | <optional> | 1 |
- Source
- Type:
- Number
(static) rgb(ropt, gopt, bopt, aopt) → {Color}
Create a color object with RGBA values
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r | Number | <optional> | 1 | |
g | Number | <optional> | 1 | |
b | Number | <optional> | 1 | |
a | Number | <optional> | 1 |
- Source
- Type:
- Color
(static) sign(value) → {Number}
Returns the sign of value passed in (also returns 1 if 0)
Name | Type | Description |
---|---|---|
value | Number |
- Source
- Type:
- Number
(static) smoothStep(value) → {Number}
Applies smoothstep function to the percentage value
Name | Type | Description |
---|---|---|
value | Number |
- Source
- Type:
- Number
(static) vec2(xopt, yopt) → {Vector2}
Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | Number | <optional> | 0 | |
y | Number | <optional> | 0 |
- Source
- Type:
- Vector2
let a = vec2(0, 1); // vector with coordinates (0, 1)
let b = vec2(a); // copy a into b
a = vec2(5); // set a to (5, 5)
b = vec2(); // set b to (0, 0)
(static) wave(frequencyopt, amplitudeopt, topt) → {Number}
Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
frequency | Number | <optional> | 1 | Frequency of the wave in Hz |
amplitude | Number | <optional> | 1 | Amplitude (max height) of the wave |
t | Number | <optional> | time | Value to use for time of the wave |
- Source
- Value waving between 0 and amplitude
- Type:
- Number