Liking cljdoc? Tell your friends :D

com.evocomputing.colors

Color manipulation routines. This code was heavily infuenced by the color.rb module in the ruby SASS project, and the colorspace packages in R.

Further references: HSL and HSV: http://en.wikipedia.org/wiki/Luminance-Hue-Saturation RGB color space: http://en.wikipedia.org/wiki/RGB_color_space http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB http://www.w3.org/TR/css3-color/#hsl-color

SASS color module: http://github.com/nex3/haml/blob/master/lib/sass/script/color.rb

R colorspace package: http://cran.r-project.org/web/packages/colorspace/index.html

Color manipulation routines. This code was heavily infuenced by the
color.rb module in the ruby SASS project, and the colorspace packages in R.


Further references:
HSL and HSV:
http://en.wikipedia.org/wiki/Luminance-Hue-Saturation
RGB color space:
http://en.wikipedia.org/wiki/RGB_color_space
http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB
http://www.w3.org/TR/css3-color/#hsl-color

SASS color module:
http://github.com/nex3/haml/blob/master/lib/sass/script/color.rb

R colorspace package:
http://cran.r-project.org/web/packages/colorspace/index.html
raw docstring

adjust-alphaclj

(adjust-alpha color unit-float-adj)

Add an amount to the alpha (transparency) of the color, keeping it within the allowable range of 0-255.

Add an amount to the alpha (transparency) of the color, keeping it
within the allowable range of 0-255.
sourceraw docstring

adjust-hueclj

(adjust-hue color degrees)

Shift the hue of the color around the color wheel by the specified number of degrees. Will wrap around if it goes below 0.0 or above 360.0.

Shift the hue of the color around the color wheel by the specified
number of degrees. Will wrap around if it goes below 0.0 or above
360.0.
sourceraw docstring

allowable-hsl-keysclj

The keyword arguments which may be used to create an HSL color.

The keyword arguments which may be used to create an HSL color.
sourceraw docstring

allowable-rgb-keysclj

The keyword arguments which may be used to create an RGB color.

The keyword arguments which may be used to create an RGB color.
sourceraw docstring

alphaclj

(alpha color)

Return the alpha (int) component of this color.

Return the alpha (int) component of this color.
sourceraw docstring

awt-colorclj

(awt-color color)

Return a java.awt.Color object using this color's rgba components.

Return a java.awt.Color object using this color's rgba components.
sourceraw docstring

blueclj

(blue color)

Return the blue (int) component of this color.

Return the blue (int) component of this color.
sourceraw docstring

check-hslclj

(check-hsl hsl)
(check-hsl h s l)

Check that every element is of the format:

  • 1st, H (Hue): Float value in the range of: 0.0 - 360.0.
  • 2nd, S (Saturation): Float value in the range: 0.0 - 100.0.
  • 3rd, L (Lightness or Luminance): Float value in the range 0.0 - 100.0.
Check that every element is of the format:
- 1st, H (Hue): Float value in the range of: 0.0 - 360.0.
- 2nd, S (Saturation): Float value in the range: 0.0 - 100.0.
- 3rd, L (Lightness or Luminance): Float value in the range 0.0 - 100.0.
sourceraw docstring

check-rgbclj

(check-rgb rgb)
(check-rgb r g b)

Check that every element in the passed in rgba sequence is an integer in the range 0 - 255.

Check that every element in the passed in rgba sequence is an
integer in the range 0 - 255.
sourceraw docstring

check-rgbaclj

(check-rgba rgba)
(check-rgba r g b a)

Check that every element in the passed in rgba sequence is an integer in the range 0 - 255.

Check that every element in the passed in rgba sequence is an
integer in the range 0 - 255.
sourceraw docstring

circle-float?clj

(circle-float? fval)

Return true if passed in float is in the range 0.0 - 360.0, false otherwise.

Return true if passed in float is in the range 0.0 - 360.0, false otherwise.
sourceraw docstring

clamp-hueclj

(clamp-hue hue)

Clamp the hue value so that it lies in the range 0.0 - 360.0.

Clamp the hue value so that it lies in the range 0.0 - 360.0.
sourceraw docstring

clamp-percent-floatclj

(clamp-percent-float pfloat)

Clamp the floating point value to be within the range 0 - 100.0.

Clamp the floating point value to be within the range 0 - 100.0.
sourceraw docstring

clamp-rgb-intclj

(clamp-rgb-int rgb-int)

Clamp the integer value to be within the range 0 - 255, the legal values for an RGB color component.

Clamp the integer value to be within the range 0 - 255, the legal
values for an RGB color component.
sourceraw docstring

clamp-unit-floatclj

(clamp-unit-float ufloat)

Clamp the floating point value to be within the range 0 - 1.0.

Clamp the floating point value to be within the range 0 - 1.0.
sourceraw docstring

colorclj

Structure representing a color. Default representation is an array of integers mapping to the respective RGB(A) values. This structure also supports holding an array of float values mapping to the respective HSL values as well

Structure representing a color. Default representation
is an array of integers mapping to the respective RGB(A)
values. This structure also supports holding an array of float
values mapping to the respective HSL values as well
sourceraw docstring

color-addclj

(color-add color1__1326__auto__ color2__1327__auto__)

Add the RGB values of two colors together, clamping each to a maximum of 255.

Add the RGB values of two colors together, clamping each to a maximum of 255.
sourceraw docstring

color-divclj

(color-div color1__1326__auto__ color2__1327__auto__)

Divide the RGB values of two colors.

Divide the RGB values of two colors.
sourceraw docstring

color-epsilonclj

The maximum resolution for color math; if any value is less than or equal to this value, it is treated as zero.

The maximum resolution for color math; if any value is less than or
equal to this value, it is treated as zero.
sourceraw docstring

color-multclj

(color-mult color1__1326__auto__ color2__1327__auto__)

Multiply the RGB values of two colors, clamping each to a maximum of 255

Multiply the RGB values of two colors, clamping each to a maximum of 255
sourceraw docstring

color-nameclj

(color-name color)

If there is an entry for this color value in the symbolic color names map, return that. Otherwise, return the hexcode string of this color's rgba integer value.

If there is an entry for this color value in the symbolic color
names map, return that. Otherwise, return the hexcode string of this
color's rgba integer value.
sourceraw docstring

color-subclj

(color-sub color1__1326__auto__ color2__1327__auto__)

Subtract the RGB values of color2 from color 1, clamping each to a minimum of 0.

Subtract the RGB values of color2 from color 1, clamping each to a
minimum of 0.
sourceraw docstring

color-toleranceclj

The tolerance for comparing the components of two colors. In general, colors are considered equal if all of their components are within this tolerance value of each other.

The tolerance for comparing the components of two colors. In general,
colors are considered equal if all of their components are within this
tolerance value of each other.
sourceraw docstring

color=clj

(color= color1 color2)

Return true if rgba components are equal, and hsl float components are within tolerance.

Return true if rgba components are equal, and hsl float components
are within tolerance.
sourceraw docstring

create-colorcljmultimethod

Create a color struct using the passed in args.

This will create a color struct that has RGBA integer values in the range:

  • R (Red): Integer in range 0 - 255
  • G (Green): Integer in range 0 - 255
  • B (Blue): Integer in range 0 - 255
  • A (Alpha): Integer in range 0 - 255, with default as 255 (100% opacity)

And HSL values with the range:

  • H (Hue): Float value in the range of: 0.0 - 360.0
  • S (Saturation): Float value in the range: 0.0 - 100.0
  • L (Lightness or Luminance): Float value in the range 0.0 - 100.0

This multimethod is very liberal in what it will accept to create a color. Following is a list of acceptable formats:

Single Arg

  • Symbolic: Either a string or keyword or symbol that matches an entry in the symbolic color pallete. Currently, this is defaults to the html4 colors map and x11 colors map, but the end user of this library can set any named palette they want.

    examples: (create-color "blue") (create-color :blue)

  • Hexstring: A hex string representation of an RGB(A) color examples: (create-color "0xFFCCAA") (create-color "#FFCCAA") (create-color "Ox80FFFF00") ;; alpha = 128

  • Integer: An integer representation of an RGB(A) color examples: (create-color 0xFFCCAA) ;; integer in hexidecimal format (create-color 16764074) ;; same integer in decimal format

  • Sequence or array of RGB(A) integers :examples (create-color [255 0 0]) (create-color [255 0 0 128]) ;;alpha = 128

  • Map of either RGB (A) kw/values or HSL(A) kw/values Allowable RGB keys: :r :red :g :green :b :blue Allowable HSL keys: :h :hue :s :saturation :l :lightness

    examples: (create-color {:r 255 :g 0 :blue 0}) (create-color {:r 255 :g 0 :blue 0 :a 128}) (create-color {:h 120.0 :s 100.0 :l 50.0}) (create-color {:h 120.0 :s 100.0 :l 50.0 :a 128})

Multiple Arg

  • Sequence or array of RGB(A) integers :examples (create-color 255 0 0) (create-color 255 0 0 128) ;;alpha = 128

  • Assoc list of either RGB (A) kw/values or HSL(A) kw/values Allowable RGB keys: :r :red :g :green :b :blue Allowable HSL keys: :h :hue :s :saturation :l :lightness

    examples: (create-color :r 255 :g 0 :blue 0) (create-color :r 255 :g 0 :blue 0 :a 128) (create-color :h 120.0 :s 100.0 :l 50.0) (create-color :h 120.0 :s 100.0 :l 50.0 :a 128)

Create a color struct using the passed in args.

This will create a color struct that has RGBA integer values in the range:
- R (Red): Integer in range 0 - 255
- G (Green): Integer in range 0 - 255
- B (Blue): Integer in range 0 - 255
- A (Alpha): Integer in range 0 - 255, with default as 255 (100% opacity)

And HSL values with the range:
- H (Hue): Float value in the range of: 0.0 - 360.0
- S (Saturation): Float value in the range: 0.0 - 100.0
- L (Lightness or Luminance): Float value in the range 0.0 - 100.0

This multimethod is very liberal in what it will accept to create a
color. Following is a list of acceptable formats:

Single Arg
- Symbolic: Either a string or keyword or symbol that matches an entry
in the symbolic color pallete. Currently, this is defaults to the
html4 colors map and x11 colors map, but the end user of this library
can set any named palette they want.

  examples:
  (create-color "blue")
  (create-color :blue)

- Hexstring: A hex string representation of an RGB(A) color
  examples:
  (create-color "0xFFCCAA")
  (create-color "#FFCCAA")
  (create-color "Ox80FFFF00") ;; alpha = 128

- Integer: An integer representation of an RGB(A) color
  examples:
  (create-color 0xFFCCAA) ;; integer in hexidecimal format
  (create-color 16764074) ;; same integer in decimal format

- Sequence or array of RGB(A) integers
  :examples
  (create-color [255 0 0])
  (create-color [255 0 0 128]) ;;alpha = 128

- Map of either RGB (A) kw/values or HSL(A) kw/values
  Allowable RGB keys: :r :red :g :green :b :blue
  Allowable HSL keys: :h :hue :s :saturation :l :lightness

  examples:
  (create-color {:r 255 :g 0 :blue 0})
  (create-color {:r 255 :g 0 :blue 0 :a 128})
  (create-color {:h 120.0 :s 100.0 :l 50.0})
  (create-color {:h 120.0 :s 100.0 :l 50.0 :a 128})

Multiple Arg
- Sequence or array of RGB(A) integers
  :examples
  (create-color 255 0 0)
  (create-color 255 0 0 128) ;;alpha = 128

- Assoc list of either RGB (A) kw/values or HSL(A) kw/values
  Allowable RGB keys: :r :red :g :green :b :blue
  Allowable HSL keys: :h :hue :s :saturation :l :lightness

  examples:
  (create-color :r 255 :g 0 :blue 0)
  (create-color :r 255 :g 0 :blue 0 :a 128)
  (create-color :h 120.0 :s 100.0 :l 50.0)
  (create-color :h 120.0 :s 100.0 :l 50.0 :a 128)
sourceraw docstring

create-color-dispatchclj

(create-color-dispatch args)
(create-color-dispatch arg & others)

Inspect the arguments and determine which version of the create-color multimethod to invoke.

Inspect the arguments and determine which version of the
create-color multimethod to invoke.
sourceraw docstring

create-color-with-metacljmacro

(create-color-with-meta & body)

Create color with type metadata.

Create color with type metadata.
sourceraw docstring

darkenclj

(darken color percent)

Decrease the lightness of the color by the specified amount, down to a minimum of 0.0.

Decrease the lightness of the color by the specified amount, down
to a minimum of 0.0.
sourceraw docstring

def-color-bin-opcljmacro

(def-color-bin-op name docstring bin-op)

Macro for creating binary operations between two colors.

Arguments name - the name of the operation.

bin-op - the function that takes two values, producing one from those. (eg: + - * /). This op will be applied pairwise to the repective color's rgba components to create a new color with the resultant rgba components.

Result color - a new color that is the result of the binary operation.

Macro for creating binary operations between two colors.

Arguments
name - the name of the operation.

bin-op - the function that takes two values, producing one from
those. (eg: + - * /). This op will be applied pairwise to the
repective color's rgba components to create a new color with the
resultant rgba components.

Result
color - a new color that is the result of the binary operation.
sourceraw docstring

desaturateclj

(desaturate color percent)

Decrease the saturation of the color by the specified amount, down to a minimum of 0.0.

Decrease the saturation of the color by the specified amount, down
to a minimum of 0.0.
sourceraw docstring

grayscaleclj

(grayscale color)

Remove all hue from the color, converting it to a gray with the same lightness level.

Remove all hue from the color, converting it to a gray with the
same lightness level.
sourceraw docstring

greenclj

(green color)

Return the green (int) component of this color.

Return the green (int) component of this color.
sourceraw docstring

hexstring-to-rgba-intclj

(hexstring-to-rgba-int hexstr)

Convert a hexadecimal string to the corresponding array of RGBA integer values.

Convert a hexadecimal string to the corresponding array of RGBA
integer values.
sourceraw docstring

hsl-to-rgbclj

(hsl-to-rgb hue saturation lightness)
Given color with HSL values return vector of r, g, b.

Based on algorithms described in:
http://en.wikipedia.org/wiki/Luminance-Hue-Saturation#Conversion_from_HSL_to_RGB
and:
http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB
and:
http://www.w3.org/TR/css3-color/#hsl-color
sourceraw docstring

hueclj

(hue color)

Return the hue (float) component of this color.

Return the hue (float) component of this color.
sourceraw docstring

hue-to-rgbclj

(hue-to-rgb m1 m2 hue)

Convert hue color to rgb components Based on algorithm described in: http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB and: http://www.w3.org/TR/css3-color/#hsl-color

Convert hue color to rgb components
Based on algorithm described in:
http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB
and:
http://www.w3.org/TR/css3-color/#hsl-color
sourceraw docstring

lightenclj

(lighten color percent)

Increase the lightness of the color by the specified amount, up to a maximum of 100.0.

Increase the lightness of the color by the specified amount, up to
a maximum of 100.0.
sourceraw docstring

lightnessclj

(lightness color)

Return the lightness (float) component of this color.

Return the lightness (float) component of this color.
sourceraw docstring

maybe-convert-alphaclj

(maybe-convert-alpha alpha)

If alpha is a float value, try to convert to integer in range 0 - 255, otherwise return as-is.

If alpha is a float value, try to convert to integer in range 0 -
255, otherwise return as-is.
sourceraw docstring

mixclj

(mix color1 color2)
(mix color1 color2 weight)

Produce a blend between two colors, optionally weighted by the given percentage. Takes the average of each of the RGB components, taking into account the opacity of each color. The weight specifies the amount of the first color that should be included in the returned color. The default value of 50.0 means that half the first color and half the second color should be used. A value of 25.0 would count the second color three times as much as the first.

Produce a blend between two colors, optionally weighted by the
given percentage. Takes the average of each of the RGB components,
taking into account the opacity of each color. The weight specifies
the amount of the first color that should be included in the
returned color. The default value of 50.0 means that half the first
color and half the second color should be used. A value of 25.0
would count the second color three times as much as the first.
sourceraw docstring

mix-hslclj

(mix-hsl color1 color2)
(mix-hsl color1 color2 weight)

Produce a blend between two colors in the HSL color space, optionally weighted by the given percentage. Takes the average of each of the HSL components (always going the shortest distance around the hue circle), taking into account the opacity of each color. The weight specifies the amount of the first color that should be included in the returned color. The default value of 50.0 means that half the first color and half the second color should be used. A value of 25.0 would count the second color three times as much as the first.

Produce a blend between two colors in the HSL color space,
optionally weighted by the given percentage. Takes the average of
each of the HSL components (always going the shortest distance
around the hue circle), taking into account the opacity of each
color. The weight specifies the amount of the first color that
should be included in the returned color. The default value of 50.0
means that half the first color and half the second color should be
used. A value of 25.0 would count the second color three times as
much as the first.
sourceraw docstring

named-colors-name-to-rgbclj

Maps the known color names to their RGB values.

Maps the known color names to their RGB values.
sourceraw docstring

named-colors-rgb-to-nameclj

Maps the nown color RGB values to their names.

Maps the nown color RGB values to their names.
sourceraw docstring

near-one?clj

(near-one? fval)

Returns true if fvalue is within color-epsilon of one.

Returns true if fvalue is within color-epsilon of one.
sourceraw docstring

near-zero-or-less?clj

(near-zero-or-less? fval)

Returns true if the fvalue is within color-epsilon of zero or less than zero.

Returns true if the fvalue is within color-epsilon of zero or less
than zero.
sourceraw docstring

near-zero?clj

(near-zero? fval)

Returns true if the fvalue is less than color-epsilon.

Returns true if the fvalue is less than color-epsilon.
sourceraw docstring

oppositeclj

(opposite color)

Shift the hue of the color halfway around the color weel, to the opposite color.

Shift the hue of the color halfway around the color weel, to the
opposite color.
sourceraw docstring

percent-float?clj

(percent-float? fval)

Return true if passed in float is in the range 0.0 - 100.0, false otherwise.

Return true if passed in float is in the range 0.0 - 100.0, false otherwise.
sourceraw docstring

redclj

(red color)

Return the red (int) component of this color.

Return the red (int) component of this color.
sourceraw docstring

rgb-hexstrclj

(rgb-hexstr color)

Return the hexcode string representation of this color.

Return the hexcode string representation of this color.
sourceraw docstring

rgb-intclj

(rgb-int color)

Return a integer (RGB) representation of this color.

Return a integer (RGB) representation of this color.
sourceraw docstring

rgb-int-from-componentsclj

(rgb-int-from-components r g b)

Convert a vector of the 3 rgb integer values into a color given in numeric rgb format.

Convert a vector of the 3 rgb integer values into a color given in
numeric rgb format.
sourceraw docstring

rgb-int-to-componentsclj

(rgb-int-to-components rgb-int)

Convert a color given in numeric rgb format into a vector of the 3 rgb integer values.

Convert a color given in numeric rgb format into a vector of the 3
rgb integer values.
sourceraw docstring

rgb-int-to-unit-floatclj

(rgb-int-to-unit-float rgb-int)

Convert the integer in range 0 - 255 to float in range 0.0 - 1.0.

Convert the integer in range 0 - 255 to float in range 0.0 - 1.0.
sourceraw docstring

rgb-int?clj

(rgb-int? rgb-int)

If the passed in value is an integer in the range 0 - 255 inclusive, return true, otherwise return false.

If the passed in value is an integer in the range 0 - 255
inclusive, return true, otherwise return false.
sourceraw docstring

rgb-to-hslclj

(rgb-to-hsl red green blue)

Given the three RGB values, convert to HSL and return vector of Hue, Saturation, Lightness.

Based on algorithm described in: http://en.wikipedia.org/wiki/Luminance-Hue-Saturation#Conversion_from_RGB_to_HSL_overview

Given the three RGB values, convert to HSL and return vector of
Hue, Saturation, Lightness.

Based on algorithm described in:
http://en.wikipedia.org/wiki/Luminance-Hue-Saturation#Conversion_from_RGB_to_HSL_overview
sourceraw docstring

rgba-hexstrclj

(rgba-hexstr color)

Return the hexcode string representation of this color.

Return the hexcode string representation of this color.
sourceraw docstring

rgba-intclj

(rgba-int color)

Return a integer (RGBA) representation of this color.

Return a integer (RGBA) representation of this color.
sourceraw docstring

rgba-int-from-componentsclj

(rgba-int-from-components r g b a)

Convert a vector of the 4 rgba integer values into a color given in numeric rgb format.

Convert a vector of the 4 rgba integer values into a color given in
numeric rgb format.
sourceraw docstring

rgba-int-to-componentsclj

(rgba-int-to-components rgba-int)

Convert a color given in numeric rgb format into a vector of the 4 rgba integer values.

Convert a color given in numeric rgb format into a vector of the 4
rgba integer values.
sourceraw docstring

saturateclj

(saturate color percent)

Increase the saturation of the color by the specified amount, up to a maximum of 100.0.

Increase the saturation of the color by the specified amount, up to
a maximum of 100.0.
sourceraw docstring

saturationclj

(saturation color)

Return the saturation (float) component of this color.

Return the saturation (float) component of this color.
sourceraw docstring

throw-if-notclj

(throw-if-not test & args)

Throws an Exception if test is false. Arguments are those documented for throwf.

Throws an Exception if test is false. Arguments are those
documented for throwf.
sourceraw docstring

unit-float-to-rgba-intclj

(unit-float-to-rgba-int fval)

Check that the passed in float is in the range 0.0 - 1.0, then convert it to the appropriate integer in the range 0 - 255.

Check that the passed in float is in the range 0.0 - 1.0, then
convert it to the appropriate integer in the range 0 - 255.
sourceraw docstring

unit-float?clj

(unit-float? fval)

Return true if passed in float is in the range 0.0 - 1.0, false otherwise.

Return true if passed in float is in the range 0.0 - 1.0, false otherwise.
sourceraw docstring

within-tolerance?clj

(within-tolerance? fval1 fval2)

Check whether the two values are close enough to be considered the same.

Check whether the two values are close enough to be considered the same.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close