Home Reference Source
public class | source

Saltire

Extends:

Division → Saltire

Saltire pattern.

Constructor Summary

Public Constructor
public

constructor(count: number, border: boolean, borderWidth: number, color: string, borderColor: string)

Creates a Saltire.

Member Summary

Public Members
public

border: *

public

Method Summary

Public Methods
public

draw(ctx: object)

Draws the Saltire on the given canvas.

public

Generate border information for the Saltire.

public

Generates a percentage width for the Saltire lines based on the seed.

Inherited Summary

From class Division
public

color: *

public

count: *

public

limit: *

public

seed: *

public

Public Constructors

public constructor(count: number, border: boolean, borderWidth: number, color: string, borderColor: string) source

Creates a Saltire.

Override:

Division#constructor

Params:

NameTypeAttributeDescription
count number

The number of Saltires in this instance. Should typically only be one.

border boolean

A boolean value to decide whether or not to draw a border based on the global seed setting.

borderWidth number

A number value to use when generating border width. This number is used in addition to the randomly generated border width determined by the seed.

color string

A hexadecimal color string.

borderColor string

A hexadecimal color string.

Example:

// Instantiates a Saltire without a border.
const saltire = new Saltire();
// Instantiates a Saltire with a border.
const saltireWithBorder = new Saltire(true);

Public Members

public border: * source

public borderWidth: * source

Public Methods

public draw(ctx: object) source

Draws the Saltire on the given canvas.

Params:

NameTypeAttributeDescription
ctx object

A canvas Context.

Example:

// Draws a Saltire on the canvas.
const saltire = new Saltire();
saltire.drawSaltire(ctx);

public generateSaltireBorder(seed: number): object source

Generate border information for the Saltire.

Params:

NameTypeAttributeDescription
seed number

A pseudo-random string generated based on a string value.

Return:

object

An object containing width and color keys.

Example:

// Returns an object with width and color keys.
const border = this.generateSaltireBorder(.123747918512398745);

See:

  • {@link module:flag-generator/utilities~generateSeed|generateSeed()} for more info about the seed.

public generateSaltireWidth(seed: number): number source

Generates a percentage width for the Saltire lines based on the seed.

Params:

NameTypeAttributeDescription
seed number

A pseudo-random string generated based on a string value.

Return:

number

A whole number used elsewhere as a percentage value.

Example:

// Returns 81, meaning 81%
saltire.generateWidth(0.8112494706388412);

See:

  • {@link module:flag-generator/utilities~generateSeed|generateSeed()} for more info about the seed.