Class CanvasTextureGen

Base class for texture generation, providing helper methods for vector math, noise functions, and color manipulation.

Hierarchy (view full)

Constructors

Properties

buffer: ImageData
ctx: CanvasRenderingContext2D
height: number
perm: number[]
width: number

Methods

  • Calculates the absolute values of the components of a vector (array).

    Parameters

    • a: number[]

      The vector.

    Returns number[]

    A new vector with the absolute values of the components.

  • Clamps a value between a minimum and maximum value.

    Parameters

    • n: number

      The value to clamp.

    • a: number

      The minimum value.

    • b: number

      The maximum value.

    Returns number

    The clamped value.

  • Calculates the dot product of two vectors (arrays).

    Parameters

    • a: number[]

      The first vector.

    • b: number[]

      The second vector.

    Returns number

    The dot product.

  • Applies a function to each component of a vector (array).

    Parameters

    • a: number[]

      The vector.

    • exp: ((v: number) => number)

      The function to apply.

        • (v): number
        • Parameters

          • v: number

          Returns number

    Returns number[]

    A new vector with the function applied to each component.

  • Gradient function for Perlin noise.

    Parameters

    • hash: number

      The hash value.

    • x: number

      The x coordinate.

    • y: number

      The y coordinate.

    • z: number

      The z coordinate.

    Returns number

    The gradient value.

  • Linear interpolation between two values.

    Parameters

    • t: number

      The interpolation factor (between 0 and 1).

    • a: number

      The first value.

    • b: number

      The second value.

    Returns number

    The interpolated value.

  • Calculates Perlin noise value at the given coordinates.

    Parameters

    • x: number

      The x coordinate.

    • y: number

      The y coordinate.

    • z: number

      The z coordinate.

    Returns number

    The Perlin noise value.

  • Calculates the absolute value of the product of two numbers and multiplies it by a scaling factor (default 255).

    Parameters

    • a: number

      The first number.

    • b: number

      The second number.

    • Optionalc: number

      The scaling factor (optional, defaults to 255).

    Returns number

    The scaled absolute product.

  • Generates a permutation table for Perlin noise.

    Parameters

    • n: number

      The size of the permutation table.

    Returns number[]

    The permutation table as an array of numbers.

  • Scales a value from one range to another.

    Parameters

    • v: number

      The value to scale.

    • w: number

      The width of the source range.

    Returns number

    The scaled value.

  • Creates a vector (array) with the given components.

    Parameters

    • x: number

      The x component.

    • y: number

      The y component.

    • z: number

      The z component.

    • Optionala: number

      The w component (optional).

    Returns number[]

    An array representing the vector.