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
- RandomGenerator - seeded random number generator
- Source
Members
(static, constant) BLACK :Color
Color - Black
- Source
(static, constant) BLUE :Color
Color - Blue
- Source
(static, constant) CYAN :Color
Color - Cyan
- Source
(static, constant) GRAY :Color
Color - Gray
- Source
(static, constant) GREEN :Color
Color - Green
- Source
(static, constant) MAGENTA :Color
Color - Magenta
- Source
(static, constant) ORANGE :Color
Color - Orange
- Source
(static, constant) PI :Number
A shortcut to get Math.PI
- Number
- Default Value
- Math.PI
- Source
(static, constant) PURPLE :Color
Color - Purple
- Source
(static, constant) RED :Color
Color - Red
- Source
(static, constant) WHITE :Color
Color - White
- Source
(static, constant) YELLOW :Color
Color - Yellow
- 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) distanceAngle(angleA, angleB) → {Number}
Returns signed wrapped distance between the two angles passed in
Name | Type | Description |
---|---|---|
angleA | Number | |
angleB | Number |
- Source
- Type:
- Number
(static) distanceWrap(valueA, valueB, wrapSizeopt) → {Number}
Returns signed wrapped distance between the two values passed in
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
valueA | Number | |||
valueB | Number | |||
wrapSize | 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, white by default
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
h | Number | <optional> | 0 | hue |
s | Number | <optional> | 0 | saturation |
l | Number | <optional> | 1 | lightness |
a | Number | <optional> | 1 | alpha |
- Source
- Type:
- Color
(static) isColor(c) → {Boolean}
Check if object is a valid Color
Name | Type | Description |
---|---|---|
c | any |
- Source
- Type:
- Boolean
(static) isIntersecting(start, end, pos, size) → {Boolean}
Returns true if a line segment is intersecting an axis aligned box
Name | Type | Description |
---|---|---|
start | Vector2 | Start of raycast |
end | Vector2 | End of raycast |
pos | Vector2 | Center of box |
size | Vector2 | Size of box |
- Source
- True if intersecting
- Type:
- Boolean
(static) isOverlapping(posA, sizeA, posB, sizeBopt) → {Boolean}
Returns true if two axis aligned bounding boxes are overlapping
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
posA | Vector2 | Center of box A | ||
sizeA | Vector2 | Size of box A | ||
posB | Vector2 | Center of box B | ||
sizeB | Vector2 | <optional> | (0,0) | Size of box B, a point if undefined |
- Source
- True if overlapping
- Type:
- Boolean
(static) isVector2(v) → {Boolean}
Check if object is a valid Vector2
Name | Type | Description |
---|---|---|
v | any |
- Source
- Type:
- Boolean
(static) lerp(percent, valueA, valueB) → {Number}
Linearly interpolates between values passed in using percent
Name | Type | Description |
---|---|---|
percent | Number | |
valueA | Number | |
valueB | Number |
- Source
- Type:
- Number
(static) lerpAngle(percent, angleA, angleB) → {Number}
Linearly interpolates between the angles passed in with wrapping
Name | Type | Description |
---|---|---|
percent | Number | |
angleA | Number | |
angleB | Number |
- Source
- Type:
- Number
(static) lerpWrap(percent, valueA, valueB, wrapSizeopt) → {Number}
Linearly interpolates between values passed in with wrapping
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
percent | Number | |||
valueA | Number | |||
valueB | Number | |||
wrapSize | 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, valueA, valueB) → {Number}
Returns what percentage the value is between valueA and valueB
Name | Type | Description |
---|---|---|
value | Number | |
valueA | Number | |
valueB | Number |
- Source
- Type:
- Number
(static) rgb(ropt, gopt, bopt, aopt) → {Color}
Create a color object with RGBA values, white by default
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r | Number | <optional> | 1 | red |
g | Number | <optional> | 1 | green |
b | Number | <optional> | 1 | blue |
a | Number | <optional> | 1 | alpha |
- Source
- Type:
- Color
(static) sign(value) → {Number}
Returns the sign of value passed in
Name | Type | Description |
---|---|---|
value | Number |
- Source
- Type:
- Number
(static) smoothStep(percent) → {Number}
Applies smoothstep function to the percentage value
Name | Type | Description |
---|---|---|
percent | 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> |
- 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