Class: Caman.Calculate

Defined in: src/core/


Various math-heavy helpers that are used throughout CamanJS.

Class Method Summary

Class Method Details

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


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


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

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


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


  • (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.


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


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

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

Generates a bezier curve given a start and end point, with two 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!


  • start (Array) 2-item array describing the x, y coordinate of the start point.
  • ctrl1 (Array) 2-item array describing the x, y coordinate of the first control point.
  • ctrl2 (Array) 2-item array decribing the x, y coordinate of the second control point.
  • end (Array) 2-item array describing the x, y coordinate of the end point.
  • 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.


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