Color Functions

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

Color Functions Support

The Fractal Science Kit fractal generator Color functions are associated with the Color object:

Object Color {
  R|Red  |H|Hue
  G|Green|S|Saturation
  B|Blue |L|Lightness |V|Value
  A|Alpha
}

The Color object has 4 fields: R, G, B, and A. These represent the Red, Green, Blue, and Alpha component of the color respectively, when working with the RGB color model. You can use these longer names if you want to. In addition, the field names H, S, L, and A, and the long names Hue, Saturation, Lightness, and Alpha, are useful when you are working with the HSL color model. Finally, the field names H, S, V, and A, and the long names Hue, Saturation, Value, and Alpha, are useful when you are working with the HSV color model. Each of the fields should be a floating point value between 0 and 1, inclusive. See HSL and HSV for details on these color models.

The following example illustrates how you would define a Color object using the object's constructor:

Color c = Color(R, G, B, A)

This example assigns a color to the variable c. The color is defined by the arguments: R, G, B, and A, passed to the constructor.

The following functions manipulate colors. Except where noted below, functions that take a color argument require the argument to be given in the RGB color model and functions that return a color return the color based on the RGB color model.

Color Color.Black() = Color(0, 0, 0, 1)
Color Color.White() = Color(1, 1, 1, 1)
Color Color.Gray(r) = Color(r, r, r, 1)

These methods return the indicated color. Color.Gray returns a gray color based on r which should be a value between 0 (black) and 1 (white).

Complex Color.ToValue(Color c)
Color Color.FromValue(n)

Color.ToValue converts the color c to a single integer value and returns the result. Color.FromValue converts the integer value given by n into a color and returns the result.

Color Color.RGBToHSL(Color c)
Color Color.HSLToRGB(Color c)
Color Color.RGBToHSV(Color c)
Color Color.HSVToRGB(Color c)
Color Color.ToGrayscale(Color c)
Complex Color.Luminance(Color c)

Color.RGBToHSL returns the HSL color given the RGB color argument c. Color.HSLToRGB returns the RGB color given the HSL color argument c. Color.RGBToHSV returns the HSV color given the RGB color argument c. Color.HSVToRGB returns the RGB color given the HSV color argument c. Color.ToGrayscale returns the RGB grayscale color given the RGB color argument c. Color.Luminance returns the luminance value for the given the RGB color argument c. Note that Color.ToGrayscale(c) equals Color.Gray(Color.Luminance(c)).

Color Color.AlphaBlend(Color c[], count)       = alpha blend of c[]
Color Color.LinearBlend(Color c0, Color c1, r) = c0*(1-r) + c1*r

Color.AlphaBlend blends the count colors in c[] based on each color's Alpha value. Color.LinearBlend uses r to interpolate between the colors c0 and c1 and returns the resulting color.

The expressions given above are pseudo-code; arithmetic operations cannot be applied to colors directly. Also, if any of the operations result in one of the color components falling outside the range 0 to 1, the value is clipped to that range.

Color Color.PowerBlend(Color c0, Color c1, depth, power, factor)

Color.PowerBlend uses depth, power, and factor, to interpolate between the colors c0 and c1 and returns the resulting color and is equivalent to the following:

Color c = Color.LinearBlend(c0, c1, factor*(1-(1-depth)^power))

depth should be a value between 0 and 1; depth of 0 is no blend, depth of 1 is full blend. power defines the power curve for the blend. factor should be a value between 0 and 1 and is the strength of the blend at maximum depth (depth=1).

Color Color.AdjustBrightness(Color c, delta)       = c + delta
Color Color.AdjustContrast(Color c, scale, center) = center + scale*(c-center)
Color Color.AdjustGamma(Color c, power)            = c^(1/power)

These functions adjust the brightness, contrast, and gamma of the given color, respectively, and return the color result. Color.AdjustBrightness adds delta to each component of the color. delta is a value between 0 and 1. Color.AdjustContrast scales each component about center. scale is a value between 0.2 and 8. center is a value between 0 and 1. Color.AdjustGamma applies power to each component. power is a value greater than 0.

The expressions given above are pseudo-code; arithmetic operations cannot be applied to colors directly. Also, if any of the operations result in one of the RGB components falling outside the range 0 to 1, the value is clipped to that range.

Color Color.Blend(type, Color c0, Color c1, power)

Color.Blend blends the 2 colors c0 and c1 based on the given type and power. type is the type of color blend to apply (see below). power is the strength of the blend and is a value between 0 and 1. Set power equal to 1 to achieve the full effect. A power of 0 simply returns c0. Color.Blend implements a set of color blends modeled after the blend modes described in an article written by Jens Gruschel. Color.Blend sets the Alpha value of resulting blended value to c0.Alpha. c1.Alpha is ignored.

The type is one of the values in the ColorBlendTypes enum defined in the built-in macros:

#define ColorBlendTypes

enum ColorBlendTypes {
  Average,       "Average"
  Multiply,      "Multiply"
  Screen,        "Screen"
  Darken,        "Darken"
  Lighten,       "Lighten"
  Difference,    "Difference"
  Negation,      "Negation"
  Exclusion,     "Exclusion"
  SoftLight,     "Soft Light"
  HardLight,     "Hard Light"
  Overlay,       "Overlay"
  Dodge,         "Dodge"
  Burn,          "Burn"
  InverseDodge,  "Inverse Dodge"
  InverseBurn,   "Inverse Burn"
  SoftDodge,     "Soft Dodge"
  SoftBurn,      "Soft Burn"
  Reflect,       "Reflect"
  Glow,          "Glow"
  Freeze,        "Freeze"
  Heat,          "Heat"
  Interpolate,   "Interpolate"
  Stamp,         "Stamp"
  Red,           "Red"
  Green,         "Green"
  Blue,          "Blue"
  Hue,           "Hue"
  Saturation,    "Saturation"
  Lightness,     "Lightness"
}
#end

Please see the article referenced below for specific details concerning the math behind each type.

For details see:

"Blend Modes."

From Jens Gruschel's PEGTOP Software site.

 

Copyright © 2004-2017 Hilbert, LLC
All rights reserved