Function
Static Public Summary | ||
public |
convertHex(hex: string): string Convert a hexadecimal color string to an rgb() string. |
|
public |
findGreaterNumber(a: *, b: *): * |
|
public |
generateCanvas(document: object, id: string, dimensions: object) Creates a canvas element and append it to the document body. |
|
public |
generateColor(seedMultiplier: number, seed: number): ...ColorObject Generates a color object from a modified seed using the tinycolor2 library. |
|
public |
generateCount(limit: number, seedMultiplier: number, seed: number): number Generates a number used for decision making based on the seed and a given multiplier. |
|
public |
generateSeed(seedString: string): * Generate the seed from a seed string. |
|
public |
generateSeedMultiplier(str: string): number Generates a seed multiplier converting the characters of the provided string to numbers name. |
|
public |
getLastDigit(n: number): number Gets the last digit from a number. |
|
public |
Turn a hexadecimal color string into an rgb() object. |
|
public |
modifySeed(seed: number, seedMultiplier: number): number Modify a seed by multiplying it by a value. |
|
public |
processAspectRatioString(aspect: string): object Takes an aspect ratio string, e.g.: 1:2, 2:3, 3:5, and returns an object with height (h) and width (w) keys. |
|
public |
pseudoShuffle(arr: Array, seed: number): Array Shuffles an array predictably using the Fisher Yates shuffle algorithm. |
|
public |
Generate a random hex color based on the seed. |
|
public |
setDimensionsFromAspectObject(aspect: object, multiplier: number): object Turn an aspect object into more realistic dimensions. |
Static Public
public convertHex(hex: string): string source
import {convertHex} from '@carwin/flag-generator/src/utilities.js'
Convert a hexadecimal color string to an rgb() string.
Params:
Name | Type | Attribute | Description |
hex | string | A hexadecimal color string. |
Example:
// Returns rgb(255, 255, 255)
convertHex('#ffffff');
public findGreaterNumber(a: *, b: *): * source
import {findGreaterNumber} from '@carwin/flag-generator/src/utilities.js'
Params:
Name | Type | Attribute | Description |
a | * | ||
b | * |
Return:
* |
public generateCanvas(document: object, id: string, dimensions: object) source
import {generateCanvas} from '@carwin/flag-generator/src/utilities.js'
Creates a canvas element and append it to the document body.
Example:
// Creates and appends the canvas with an id of 'myCanvas'.
generateCanvas(document, 'myCanvas');
public generateColor(seedMultiplier: number, seed: number): ...ColorObject source
import {generateColor} from '@carwin/flag-generator/src/utilities.js'
Generates a color object from a modified seed using the tinycolor2 library.
Example:
// Generates a ColorObject with a primary color key of #575109;
const colorObject = generateColor(80857473, 0.06556305047688744);
public generateCount(limit: number, seedMultiplier: number, seed: number): number source
import {generateCount} from '@carwin/flag-generator/src/utilities.js'
Generates a number used for decision making based on the seed and a given multiplier.
Example:
// Returns 1
generateCount(5, 0.8112494706388412, 0.6568774660735);
public generateSeed(seedString: string): * source
import {generateSeed} from '@carwin/flag-generator/src/utilities.js'
Generate the seed from a seed string.
Params:
Name | Type | Attribute | Description |
seedString | string | A string on which to run the prng function. |
Return:
* |
Example:
// Returns 0.8112494706388412
generateSeed('test');
public generateSeedMultiplier(str: string): number source
import {generateSeedMultiplier} from '@carwin/flag-generator/src/utilities.js'
Generates a seed multiplier converting the characters of the provided string to numbers name.
Params:
Name | Type | Attribute | Description |
str | string | A string value to turn into charcodes. |
Example:
// Returns 0.5363260631705106
generateSeedMultiplier('Border');
TODO:
- I've read somewhere that parseFloat is dangerous without radx, I should figure out if that's true. @todo: handle the case where settings.seed may not be set.
public getLastDigit(n: number): number source
import {getLastDigit} from '@carwin/flag-generator/src/utilities.js'
Gets the last digit from a number.
Params:
Name | Type | Attribute | Description |
n | number | A number. |
Example:
// Returns 7
getLastDigit(.2357);
public hexToRgb(hex: string): {r: number, b: number, g: number} source
import {hexToRgb} from '@carwin/flag-generator/src/utilities.js'
Turn a hexadecimal color string into an rgb() object.
Params:
Name | Type | Attribute | Description |
hex | string | A hexadecimal color string. |
Example:
// returns {r: 255, g: 255, b: 255}
hexToRgb('#ffffff');
public modifySeed(seed: number, seedMultiplier: number): number source
import {modifySeed} from '@carwin/flag-generator/src/utilities.js'
Modify a seed by multiplying it by a value.
Example:
// Returns 0.05483563
modifySeed(0.2602354456965794, 0.2107154537);
public processAspectRatioString(aspect: string): object source
import {processAspectRatioString} from '@carwin/flag-generator/src/utilities.js'
Takes an aspect ratio string, e.g.: 1:2, 2:3, 3:5, and returns an object with height (h) and width (w) keys.
Params:
Name | Type | Attribute | Description |
aspect | string | A string describing a ratio. |
Return:
object | An aspect ratio object containing height (h) and width (w) keys from the aspect ratio string. |
Example:
// Returns
// {
// h: 3,
// w: 5,
// }
const aspectObject = processAspectRatioString('3:5');
TODO:
- This function could be shortened significantly with a map callback.
public pseudoShuffle(arr: Array, seed: number): Array source
import {pseudoShuffle} from '@carwin/flag-generator/src/utilities.js'
Shuffles an array predictably using the Fisher Yates shuffle algorithm.
Example:
// Returns [1, 2, 3, 5, 4]
const originalArray = [1, 2, 3, 4, 5]
const shuffledArray = pseudoShuffle(originalArray, 0.7243609520746538);
public randomHex(seed: number, seedModifier: number): string source
import {randomHex} from '@carwin/flag-generator/src/utilities.js'
Generate a random hex color based on the seed.
Example:
// returns #2b32ad
randomHex(0.8112494706388412);
public setDimensionsFromAspectObject(aspect: object, multiplier: number): object source
import {setDimensionsFromAspectObject} from '@carwin/flag-generator/src/utilities.js'
Turn an aspect object into more realistic dimensions.
Example:
// Returns
// {
// h: 300,
// w: 500,
// }
const dimensions = setDimensionsFromAspectObject({h: 3, w: 5});