Gradient Functions

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

Gradient Functions Support

The Fractal Science Kit fractal generator Gradient functions are supported in the following programs:

Each of these programs has an associated array of Gradients defined by the Gradient List Control on the color controller's properties page. Both the number of gradients and the color/opacity information in each gradient is set there.

The following functions provides access to these gradients:

Complex Gradient.Count()
Color Gradient.Color(index, position)
Color Gradient.Opacity(index, position)

Gradient.Count returns the number of gradients in the array of gradients. Gradient.Color returns the color at position in the gradient item given by index. The color returned by Gradient.Color includes the opacity value in the color's Alpha field. Gradient.Opacity returns the opacity at position in the gradient item given by index.

The index argument in each function is an integer index into the array of gradients. The gradient items in the array correspond to index values 0 to Gradient.Count()-1. If index is outside this range, the value is wrapped around at each extreme into the valid range. For example, an index value of Gradient.Count() would become 0 when wrapped, and an index value of -1 would become Gradient.Count()-1. index is truncated to an integer before use.

The position argument in each function represents a position within the gradient. Values that range from 0 to 1 cover the entire gradient. If position is outside this range, the value is wrapped around at each extreme.

Example:

color = Gradient.Color(0, Sample.Magnitude)

This example maps the sample's normalized magnitude to a color using the 1st gradient in the array (i.e., gradient 0).

Example:

comment:
 
  Maps a sample point value to a gradient index.
 
color:
 
  color = Gradient.Color(ColorScheme, Value)
 
properties:
 
 option ColorScheme {
    type = GradientIndex
    caption = "Color Scheme"
    default = 0
    size = Large
  }
  option Value {
    type = SamplePointValue
    caption = "Value"
    default = Sample.Magnitude
  }

In this example, the controller maps a user selected SamplePointValue Option to a gradient index thereby obtaining a color. The controller calls the function Gradient.Color(ColorScheme,Value) to map the sample data to a color using the gradient in the controller's list of gradients indexed by ColorScheme. See GradientIndex Options for details.

Example:

color:
 
  color = Gradient.Color( \
    Offset2 + Factor2*Value2^Power2, \
    Offset1 + Factor1*Value1^Power1  \
  )
 
properties:
 
  divider {
    caption = "Value"
  }
  option Value1 {
    type = SamplePointValue
    caption = "Value"
    default = Sample.Magnitude
  }
  option Power1 {
    type = Float
    caption = "Power"
    details = "Set value = value ^ Power (0.125 to 8)"
    default = 1
    range = [0.125,8]
  }
  option Factor1 {
    type = Float
    caption = "Factor"
    details = "Set value = value * Factor (-8 to 8)"
    default = 1
    range = [-8,8]
  }
  option Offset1 {
    type = Float
    caption = "Offset"
    details = "Set value = value + Offset (-1 to 1)"
    default = 0
    range = [-32,32]
  }
  divider {
    caption = "Overlay"
  }
  option Value2 {
    type = SamplePointValue
    caption = "Overlay"
    default = Sample.Alternate1Value
  }
  option Power2 {
    type = Float
    caption = "Power"
    details = "Set overlay = overlay ^ Power (0.125 to 8)"
    default = 1
    range = [0.125,8]
  }
  option Factor2 {
    type = Float
    caption = "Factor"
    details = "Set overlay = overlay * Factor (0 to 32)"
    default = 8
    range = (0,32]
  }
  option Offset2 {
    type = Float
    caption = "Offset"
    details = "Set overlay = overlay + Offset (-1 to 1)"
    default = 0
    range = [-1,1]
  }

In this example we call the function Gradient.Color to map the sample to a color and use Value2 to select 1 of the gradients in the controller's list, and use Value1 to index into the selected gradient to obtain a color. Gradient.Color wraps both arguments at the extremes. The 1st argument is an integer index into the list of gradients. For example, if the gradient list contains 2 gradients, even values map to the 1st gradient and odd values map to the 2nd gradient. The argument is truncated to an integer before use. The 2nd argument to Gradient.Color is a real number between 0 and 1. Values outside this range are wrapped before selecting the color. For example, passing 1.2 would return the color at position 0.2.

 

Copyright © 2004-2017 Hilbert, LLC
All rights reserved