Class: Caman.Calculate

Defined in: src/core/calculate.coffee

Overview

Various math-heavy helpers that are used throughout CamanJS.

Class Method Summary

Class Method Details

+ (Number) distance(x1, y1, x2, y2)

Parameters:

  • x1 (Number) 1st point x-coordinate.
  • y1 (Number) 1st point y-coordinate.
  • x2 (Number) 2nd point x-coordinate.
  • y2 (Number) 2nd point y-coordinate.

Returns:

  • (Number) — The distance between the two points.

+ (Number) randomRange(min, max, getFloat = false)

Parameters:

  • min (Number) The lower bound (inclusive).
  • max (Number) The upper bound (inclusive).
  • getFloat (Boolean) Return a Float or a rounded Integer?

Returns:

  • (Number) — The pseudorandom number, either as a float or integer.

+ (Number) luminance(rgba)

Calculates the luminance of a single pixel using a special weighted sum.

Parameters:

  • rgba (Object) RGBA object describing a single pixel.

Returns:

  • (Number) — The luminance value of the pixel.

+ (Array) bezier(start, ctrl1, ctrl2, end, lowBound = 0, highBound = 255)

Generates a bezier curve given a start and end point, with control points in between. Can also optionally bound the y values between a low and high bound.

This is different than most bezier curve functions because it attempts to construct it in such a way that we can use it more like a simple input -> output system, or a one-to-one function. In other words we can provide an input color value, and immediately receive an output modified color value.

Note that, by design, this does not force X values to be in the range [0..255]. This is to generalize the function a bit more. If you give it a starting X value that isn't 0, and/or a ending X value that isn't 255, you may run into problems with your filter!

Parameters:

  • 2-item (Array) arrays describing the x, y coordinates of the control points. Minimum two.
  • lowBound (Number) (optional) Minimum possible value for any y-value in the curve.
  • highBound (Number) (optional) Maximum posisble value for any y-value in the curve.

Returns:

  • (Array) — Array whose index represents every x-value between start and end, and value represents the corresponding y-value.

+ (Array) hermite(controlPoints, lowBound, highBound)

Generates a hermite curve given a start and end point, with control points in between. Can also optionally bound the y values between a low and high bound.

This is different than most hermite curve functions because it attempts to construct it in such a way that we can use it more like a simple input -> output system, or a one-to-one function. In other words we can provide an input color value, and immediately receive an output modified color value.

Note that, by design, this does not force X values to be in the range [0..255]. This is to generalize the function a bit more. If you give it a starting X value that isn't 0, and/or a ending X value that isn't 255, you may run into problems with your filter!

Parameters:

  • 2-item (Array) arrays describing the x, y coordinates of the control points. Minimum two.
  • lowBound (Number) (optional) Minimum possible value for any y-value in the curve.
  • highBound (Number) (optional) Maximum possible value for any y-value in the curve.

Returns:

  • (Array) — Array whose index represents every x-value between start and end, and value represents the corresponding y-value.

+ (Array) missingValues(values, endX)

Calculates possible missing values from a given value array. Note that this returns a copy and does not mutate the original. In case no values are missing the original array is returned as that is convenient.

Parameters:

  • 2-item (Array) arrays describing the x, y coordinates of the control points.
  • end (Number) x value of the array (maximum)

Returns:

  • (Array) — Array whose index represents every x-value between start and end, and value represents the corresponding y-value.