Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
version: * The version of the module. |
Private Members | ||
private |
The logger module this module uses to log errors / logs |
|
private |
An array storing all the reserved unique IDS |
|
private |
Object storing all color objects being transitioned at the moment |
Method Summary
Public Methods | ||
public |
addIntensity(pColor: string | number, pPercent: number): * Add intensity to this color to get a brighter or dimmer effect |
|
public |
calculateIconOffset(pIconSize: Object, pAnchor: Object, pScale: Object): Object Calculate the icon offset to compensate for a non-zero anchor. |
|
public |
calculateNewPositionFromDistanceAndAngle(pPoint: Object, pDistance: number, pAngle: number): Object Calculates the new position of a point based on distance and angle. |
|
public |
calculateProportionalLength(pCurrent: number, pMax: number, pTotalLength: number): number Calculates the proportional length based on a current value, a maximum value, and a specified total length. |
|
public |
cancelTransitionColor(pID: string) Cancels an ongoing transition |
|
public |
centerRectangleOnParent(pChildWidth: number, pChildHeight: number, pParentWidth: number, pParentHeight: number, pParentX: number, pParentY: number): Object Centers a rectangle (defined by its dimensions) within a parent rectangle. |
|
public |
Clamps a number between a minimum and maximum value. |
|
public |
convertRaWAngleToVyloCoords(pAngle: number): * Converts a raw angle to be the proper angle in Vylocity. |
|
public |
decimalRand(pNum1: number, pNum2: number, pPlaces: number): number Generates a random decimal number between two numbers with a specified number of decimal places. |
|
public |
decimalToHex(pDecimal: number, pChars: number): * Converts a color in decimal format into hex format |
|
public |
flooredLerp(pStart: number, pEnd: number, pAmount: number): number Linearly interpolates between two values by a specified amount and returns the result as a floored integer. |
|
public |
formatIntegerWithCommas(pNum: number): string Formats a number by rounding it to the nearest integer and adding commas to separate thousands places. |
|
public |
generateID(pIDLength: string): * Generates a unique id |
|
public |
Gets the angle between two points |
|
public |
Gets the angle between two points but in VYLO / PIXI coordinate space. |
|
public |
getAngleFromDirection(pDirection: string): number Calculates the angle (in radians) from a given direction. |
|
public |
getDirection(pAngle: number): string Calculates the compass direction based on the given angle. |
|
public |
getDistance(pStartPoint: Object, pEndPoint: Object): number Calculates the Euclidean distance between two points in a two-dimensional space. |
|
public |
getInverseDirection(pDirection: string): string Gets the inverse direction of the direction passed |
|
public |
getPercentage(pValue: number, pTotalValue: number): number Calculates the percentage of a value relative to a total value. |
|
public |
getPointRotated(pRect: object, pTheta: number, pPoint: object): object Calculates the position of a point after rotating it around a center point by a given angle. |
|
public |
getPointsOfRotatedRect(pRect: object, pTheta: number): object Calculates the position of a rectangle's corner points and center point after rotating it around a center point by a given angle. |
|
public |
Generates a random angle in radians. |
|
public |
Gets a random color |
|
public |
Gets a random color between two colors |
|
public |
Convert a color to different formats or get a random color |
|
public |
hexToDecimal(pHex: string): number Converts a hexadecimal color value to a decimal value. |
|
public |
Converts a hexadecimal color value to an RGB color value. |
|
public |
Linearly interpolates between two values by a specified amount. |
|
public |
linearDecay(pInitialValue: number, pCurrentTime: number, pMaxTime: number, pDecayRate: number): number Calculates the linear decay of a variable over time. |
|
public |
Normalizes a value between a minimum and maximum value. |
|
public |
normalizeRanged(pVal: number, pMin: number, pMax: number): number Normalizes a value between a minimum and maximum value, clamped to the range of -1 to 1. |
|
public |
Returns a random element from the given array. |
|
public |
Returns true with probability proportional to the given number. |
|
public |
Generates a random decimal number between two numbers with a specified number of decimal places. |
|
public |
removeProperties(pObject: object, pExclude: Array) Removes properties from an object except those listed in the exclude array. |
|
public |
rgbToDecimal(pR: number, pG: number, pB: number): * Converts RGB color values to a decimal value. |
|
public |
Converts an RGB color value to a hexadecimal color value. |
|
public |
Rounds a number to a specified number of decimal places. |
|
public |
Converts radians to degrees. |
|
public |
Converts degrees to radians. |
|
public |
transitionColor(pInstance: Object, pStartColor: string | number, pEndColor: string | number, pDuration: number, pIterativeCallback: Function, pEndCallback: Function): * Transition a color to another color in pDuration time. |
|
public |
Checks if a value is within a range of minimum and maximum values (inclusive). |
Public Constructors
public constructor() source
Public Members
Private Members
Public Methods
public addIntensity(pColor: string | number, pPercent: number): * source
Add intensity to this color to get a brighter or dimmer effect
Return:
* |
public calculateIconOffset(pIconSize: Object, pAnchor: Object, pScale: Object): Object source
Calculate the icon offset to compensate for a non-zero anchor.
Params:
Name | Type | Attribute | Description |
pIconSize | Object |
|
The size of the icon with properties |
pIconSize.width | number |
|
The size of the icon's width. |
pIconSize.height | number |
|
The size of the icon's height'. |
pAnchor | Object |
|
The anchor point with properties |
pAnchor.x | number |
|
The anchor's x value. |
pAnchor.y | number |
|
The anchor's y value. |
pScale | Object |
|
The scale factor applied to the object with properties |
pScale.x | number |
|
The scale's y value. |
pScale.y | number |
|
The scale's y value. |
public calculateNewPositionFromDistanceAndAngle(pPoint: Object, pDistance: number, pAngle: number): Object source
Calculates the new position of a point based on distance and angle.
Params:
Name | Type | Attribute | Description |
pPoint | Object | The initial position of the point with x and y coordinates. |
|
pPoint.x | number | The initial x-coordinate of the point. |
|
pPoint.y | number | The initial y-coordinate of the point. |
|
pDistance | number | The distance by which to move the point. |
|
pAngle | number | The angle (in radians) at which to move the point. |
Example:
const initialPosition = { x: 10, y: 20 };
const distance = 5;
const angleInRadians = 0.785398; // 45 degrees
const newPosition = calculateNewPositionFromDistanceAndAngle(initialPosition, distance, angleInDegrees);
// Returns the new position of the point after moving by 5 units at a 45-degree angle.
public calculateProportionalLength(pCurrent: number, pMax: number, pTotalLength: number): number source
Calculates the proportional length based on a current value, a maximum value, and a specified total length.
Example:
const current = 25;
const max = 50;
const totalLength = 100;
const proportionalLength = calculateProportionalLength(current, max, totalLength); // 50
// Returns the proportional length based on the current value, maximum value, and total length.
public cancelTransitionColor(pID: string) source
Cancels an ongoing transition
Params:
Name | Type | Attribute | Description |
pID | string | The ID of the ongoing transition to cancel |
public centerRectangleOnParent(pChildWidth: number, pChildHeight: number, pParentWidth: number, pParentHeight: number, pParentX: number, pParentY: number): Object source
Centers a rectangle (defined by its dimensions) within a parent rectangle.
Params:
Name | Type | Attribute | Description |
pChildWidth | number | The width of the child rectangle. |
|
pChildHeight | number | The height of the child rectangle. |
|
pParentWidth | number | The width of the parent rectangle. |
|
pParentHeight | number | The height of the parent rectangle. |
|
pParentX | number | The x-coordinate of the parent rectangle. |
|
pParentY | number | The y-coordinate of the parent rectangle. |
Return:
Object | An object representing the new coordinates of the centered rectangle: { x: centerX, y: centerY }. |
Example:
const childWidth = 50;
const childHeight = 30;
const parentWidth = 100;
const parentHeight = 80;
const parentX = 20;
const parentY = 10;
const centeredCoordinates = centerRectangleOnParent(childWidth, childHeight, parentWidth, parentHeight, parentX, parentY);
// Returns {x: 45, y: 35}
public clamp(pNumber: number, pMin: number, pMax: number): number source
Clamps a number between a minimum and maximum value.
public convertRaWAngleToVyloCoords(pAngle: number): * source
Converts a raw angle to be the proper angle in Vylocity. By removing 180 degrees
Params:
Name | Type | Attribute | Description |
pAngle | number | The angle to convert. |
Return:
* | The converted angle |
public decimalRand(pNum1: number, pNum2: number, pPlaces: number): number source
Generates a random decimal number between two numbers with a specified number of decimal places.
Params:
Name | Type | Attribute | Description |
pNum1 | number | The first number to use for generating the random decimal number. |
|
pNum2 | number | The second number to use for generating the random decimal number. |
|
pPlaces | number |
|
The number of decimal places to include in the generated random decimal number. Defaults to 1 if not provided. |
Return:
number | A random decimal number between the two numbers with the specified number of decimal places. |
public decimalToHex(pDecimal: number, pChars: number): * source
Converts a color in decimal format into hex format
Return:
* | The decimal color converted into hex format |
public flooredLerp(pStart: number, pEnd: number, pAmount: number): number source
Linearly interpolates between two values by a specified amount and returns the result as a floored integer.
Return:
number | The interpolated value between the start and end values based on the specified amount, rounded down to the nearest integer. |
public formatIntegerWithCommas(pNum: number): string source
Formats a number by rounding it to the nearest integer and adding commas to separate thousands places.
Params:
Name | Type | Attribute | Description |
pNum | number | The number to format. |
public generateID(pIDLength: string): * source
Generates a unique id
Params:
Name | Type | Attribute | Description |
pIDLength | string | The length of the ID to create |
Return:
* | A unique ID |
public getAngle(pStartPoint: Object, pEndPoint: Object): number source
Gets the angle between two points
public getAngle2(pStartPoint: Object, pEndPoint: Object): number source
Gets the angle between two points but in VYLO / PIXI coordinate space. Removes 180 degrees from a raw angle
public getAngleFromDirection(pDirection: string): number source
Calculates the angle (in radians) from a given direction.
Params:
Name | Type | Attribute | Description |
pDirection | string | The direction to calculate the angle from. |
Throw:
Throws an error if the direction is not recognized. |
public getDirection(pAngle: number): string source
Calculates the compass direction based on the given angle.
Params:
Name | Type | Attribute | Description |
pAngle | number | The angle in radians. |
Example:
const angle = Math.PI / 4; // 45 degrees in radians
const direction = getDirection(angle); // Returns 'northeast'
public getDistance(pStartPoint: Object, pEndPoint: Object): number source
Calculates the Euclidean distance between two points in a two-dimensional space.
Params:
Name | Type | Attribute | Description |
pStartPoint | Object | The starting point with x and y coordinates. |
|
pStartPoint.x | number | The x-coordinate of the starting point. |
|
pStartPoint.y | number | The y-coordinate of the starting point. |
|
pEndPoint | Object | The ending point with x and y coordinates. |
|
pEndPoint.x | number | The x-coordinate of the ending point. |
|
pEndPoint.y | number | The y-coordinate of the ending point. |
Example:
const startPoint = { x: 1, y: 2 };
const endPoint = { x: 4, y: 6 };
const distance = getDistance(startPoint, endPoint); // 5
// Returns the Euclidean distance between the points (1, 2) and (4, 6).
public getInverseDirection(pDirection: string): string source
Gets the inverse direction of the direction passed
Params:
Name | Type | Attribute | Description |
pDirection | string | The direction to get the inverse of. |
public getPercentage(pValue: number, pTotalValue: number): number source
Calculates the percentage of a value relative to a total value.
public getPointRotated(pRect: object, pTheta: number, pPoint: object): object source
Calculates the position of a point after rotating it around a center point by a given angle.
Params:
Name | Type | Attribute | Description |
pRect | object | The rectangle object to rotate the point around. pRect.anchor.x and pRecent.anchor.y is used to control the "center" of the rectangle. |
|
pTheta | number | The angle (in radians) to rotate the point by. |
|
pPoint | object | The point object to rotate around the center of the rectangle. |
|
pPoint.x | number | The x-coordinate of the point to rotate. |
|
pPoint.y | number | The y-coordinate of the point to rotate. |
public getPointsOfRotatedRect(pRect: object, pTheta: number): object source
Calculates the position of a rectangle's corner points and center point after rotating it around a center point by a given angle.
public getRandomColorBetween(pColor1: number | string, pColor2: number | string, pAmount: number): string source
Gets a random color between two colors
Params:
Name | Type | Attribute | Description |
pColor1 | number | string | The first color to get a color between |
|
pColor2 | number | string | The second color to get a color between |
|
pAmount | number |
|
The closer the random color will be to either input colors on a range of 0-1 0 to 0.5 (closer to pColor1) 0.5 to 1 (closer to pColor2) |
public grabColor(pSwitch: string | number, g: number, b: number): ColorObject source
Convert a color to different formats or get a random color
Return:
ColorObject | A color object with various different export options. hex, hexTagless, rgb, rgbArray, rgbObject, rgbNormal, decimal formats. |
public hexToDecimal(pHex: string): number source
Converts a hexadecimal color value to a decimal value.
Params:
Name | Type | Attribute | Description |
pHex | string | The hexadecimal color value to convert (e.g. "#FF0000" for red). |
public hexToRgb(pHex: string): Array source
Converts a hexadecimal color value to an RGB color value.
Params:
Name | Type | Attribute | Description |
pHex | string | The hexadecimal color value to convert (e.g. "#FF0000" for red). |
public lerp(pStart: number, pEnd: number, pAmount: number): number source
Linearly interpolates between two values by a specified amount.
Return:
number | The interpolated value between the start and end values based on the specified amount. |
public linearDecay(pInitialValue: number, pCurrentTime: number, pMaxTime: number, pDecayRate: number): number source
Calculates the linear decay of a variable over time.
Params:
Name | Type | Attribute | Description |
pInitialValue | number | The initial value of the variable. |
|
pCurrentTime | number | The current time at which to calculate the variable value. |
|
pMaxTime | number | The maximum time for the decay process. |
|
pDecayRate | number |
|
The decay rate (default is 0.5). |
Example:
const initialValue = 100;
const currentTime = 50;
const maxTime = 1000;
const decayRate = 0.3;
const remainingValue = linearDecay(initialValue, currentTime, maxTime, decayRate);
// Returns the remaining value after linear decay.
public normalize(pVal: number, pMin: number, pMax: number): number source
Normalizes a value between a minimum and maximum value.
Return:
number | The normalized value between 0 and 1 based on the input value's position between the minimum and maximum values. If the difference between pMax and pMin is 0, returns 1 to avoid dividing by zero. |
public normalizeRanged(pVal: number, pMin: number, pMax: number): number source
Normalizes a value between a minimum and maximum value, clamped to the range of -1 to 1.
Return:
number | The normalized and clamped value between -1 and 1 based on the input value's position between the minimum and maximum values. If the difference between pMax and pMin is 0, returns 1 to avoid dividing by zero. |
public pick(pArray: Array): * source
Returns a random element from the given array.
Params:
Name | Type | Attribute | Description |
pArray | Array | The input array. |
Return:
* | A random element from the array. |
public prob(pChance: number): boolean source
Returns true with probability proportional to the given number. The higher the number, the higher the chance of returning true.
Params:
Name | Type | Attribute | Description |
pChance | number | The probability value, between 0 and 100 (inclusive). |
public rand(pNum1: number, pNum2: number): number source
Generates a random decimal number between two numbers with a specified number of decimal places.
Return:
number | A random decimal number between the two numbers with the specified number of decimal places. |
public removeProperties(pObject: object, pExclude: Array) source
Removes properties from an object except those listed in the exclude array.
public rgbToDecimal(pR: number, pG: number, pB: number): * source
Converts RGB color values to a decimal value.
Return:
* |
public rgbToHex(pR: number, pG: number, pB: number): * source
Converts an RGB color value to a hexadecimal color value.
Return:
* |
public round(pNumber: number, pPlace: number): number source
Rounds a number to a specified number of decimal places.
public toDegrees(pRadians: number): number source
Converts radians to degrees.
Params:
Name | Type | Attribute | Description |
pRadians | number | The angle in radians. |
public toRadians(pDegrees: number): number source
Converts degrees to radians.
Params:
Name | Type | Attribute | Description |
pDegrees | number | The angle in degrees. |
public transitionColor(pInstance: Object, pStartColor: string | number, pEndColor: string | number, pDuration: number, pIterativeCallback: Function, pEndCallback: Function): * source
Transition a color to another color in pDuration time.
Params:
Name | Type | Attribute | Description |
pInstance | Object | The instance to transition it's color property. pInstance's color will be transitioned either via pInstance.color = newColor or pInstance.color.tint = newColor (if the color is defined as an object) |
|
pStartColor | string | number | The start color |
|
pEndColor | string | number | The end color |
|
pDuration | number | The duration of the transition |
|
pIterativeCallback | Function | Callback to call every tick of the transition |
|
pEndCallback | Function | Callback to call at the end of the transition |
Return:
* | An ID that references this transition to be passed to cancelTransition to stop an ongoing transition. |