2.5. Appearance in 2D (2): Colors and fills

In many parts of Anableps there is place to specify the color or the aspect of some shape or the surface of a body. There are several objects that can fill in the slot:

  • A color:
  • A painter, that takes pair of coordinates (can be coordinates of the surface or other function of them) and returns a color
  • An appearance. Appearance is color + shine + emmitance + transparence. It has an effect in some renderers
  • Textures, that can modify normals, too.

asdfsafd

  • Color: the color of the body
  • Shine: how the light bounces off the surface, depending on the angle
  • Emitance: is the object emitting light?
  • Textures: sometimes a decal is applied on the surface, so each part of the body hsa a different color. Textures apply only to change color

2.5.1. Colors

There are several non-exclusive ways to define colors:

  • color names: some predefined color have a name, like yellow or alizarine blue
  • color spaces: colors can be specified by its point components in some color space. Examples are rgb100(50,20,30) or hsv(0.4, 0.2, 0.2).
  • color modifiers. Given a color, it can be tweaked: darkish blue
  • color formulas, combining other colors using operators: 5 * yellow + 2 * blue. This combination can be additive or substractive.

2.5.1.1. Color names

There are several standard lists of color names. X11 names, web names, crayola, etc. you can use any of them for defining a shape or a body:

cone c: .color crimson_red

The accepted color lists can be found in the appendixes:

2.5.1.2. Color modifiers

Modifiers act as operators

  • bluish <color>, bluer <color>, bluest <color>: same as blue * 0.2 + <color> * 0.8
  • reddish, redder, reddest: same as blue * 0.2 + <color> * 0.8
  • darkish, darker, darkest: same as blue * 0.2 + <color> * 0.8
  • lightish, lighter, lightest: same blue * 0.2 + <color> * 0.8

2.5.1.3. Color spaces

Color can be specified, too, by setting its components. There are several color spaces available:

  • rgb(r, g, b): red, green and blue components. There are several variants of the rgb color space regarding the ranges:
    • rgb1(r,g,b): red green and blue (and optionally an alpha value) in the range 0..1.
    • rgb100(r,g,b): red, green and blue components (and optionally an alpha value) in the range 0..100.
    • rgb255(r,g,b): red, green and blue components (and optionally an alpha value) in the range 0..255.
  • hsv(h, s, v): hue
    • hsv(r,g,b): hue, saturation and value in the range 0..1.
    • hsv100(r,g,b): hue, saturation and value in the range 0..100.
    • hsv255(r,g,b): hue, saturation and value in the range 0..255.
  • cmyk(c,m,y, k):
    • cmyk1(c,m,y, k): cyan, magenta, yellow and black, in the range 0..1.
    • cmyk100(c,m,y, k): cyan, magenta, yellow and black, in the range 0..1.
    • cmyk255(c,m,y, k): cyan, magenta, yellow and black, in the range 0..1.

2.5.1.4. Color formulas and quantities

Given the many ways of specifying simple colors, color is a language type and accordingly, expressions can be constructed combining several colors. Currently allowed operations with colors are addition, substraction and multiplication by a number. For example:

sphere s1: .color red + yellow

Multiplication by a number modifies the quantity of the color. If no quantity is specified, colors have a quantity of 1. This term is only relevant when mixing two colors, and regulates how much of each color is put into the mix. For single colors it has no effect whatsoever: the following colors yellow and 5 * yellow represent the same color. However, when mixing:

bleps> 5 * red + 4 * blue
<color (1.0, 0, 0.8)>

Note that the resulting colors keep memory of the quantities. For example:

5 * red + 4 * blue = 9 * magenta

The quantity of a color can be changed using the function take:

(5 * red + 4 * blue).take(1) + (2 * yellow)

2.5.1.5. Alpha channels

Alpha channel for a color can be specified as the fourth element in the tuples, for any color space (rgb, rgb100, rgb255, cmy, etc).

What happens on additions?

Sometimes is it useful to set the alpha channel after a color formula. This can be achieved with the operator .alpha:

color c = (2 * red + 5 * yellow).alpha(50%)
color c = (2 * red + 5 * yellow) ~ alpha(50%)

2.5.1.6. Other blending modes

Although of no much importance, there is lighten, darken, screen, multiply, dodge, burn blending modes. These can be accessed through the functions:

  • dodge(colora, colorb): and so on

2.5.2. Color Palettes

asdfasf

2.5.3. Color functions

Sometimes a function instead of a color can be given when a color input is expected. The function takes the x and y coordinates and returns a color. In this way

2.5.4. Fill attributes

For the color, a painter can be input in place of a color. A painter is an object that instead of returning always the same color, changes it according with some result applied to the coordinates. See colorizer to understand how they work.

2.5.4.1. Attributes

  • .color : the color
  • .pattern : the pattern, if any
  • .gradient : is there any gradient?

2.5.4.1.1. Examples

an example