Blend

Blend[{col1,col2},x]

gives a color obtained by blending a fraction of color col1 and of color col2.

Blend[{col1,col2,col3,},x]

linearly interpolates between colors coli as x varies from 0 to 1.

Blend[{{x1,col1},{x2,col2},},x]

interpolates to give coli when x=xi.

Blend[{col1,col2,},{u1,u2,}]

blends all the coli, using fraction ui of color coli.

Blend[{image1,image2,},]

blends pixel values of 2D or 3D images imagei.

Details

  • Blend implements additive color mixing as appropriate for colored light sources or lightgenerating displays.
  • In Blend[{col1,,coln},{u1,,un}], the ui are normalized to have total 1. »
  • Blend[{col1,col2,}] blends equal fractions of all the coli.
  • In Blend[{image1,image2},x], if image1 and image2 are of different dimensions, linear interpolation of the dimensions is used.
  • Blend[{image,col},x] blends every pixel of image with the color col.
  • In Blend[{image1,col1,,coln,image2},x], coli is interpreted as an image whose dimensions are taken from a linear interpolation between dimensions of image1 and image2.

Examples

open allclose all

Basic Examples  (5)

Blend two colors by fractions:

Generate an array of blended colors ranging from red to blue:

Represent the height as a blend from yellow to purple:

Average two colors equally:

Blend pixels of an image with a color:

Scope  (10)

Colors  (5)

Linear interpolation between two colors:

Linear interpolation between two colors and two opacities:

Linear interpolation between multiple colors uniformly:

Linear interpolation between colors at specific values:

Blending colors with equal weights:

Blending colors with specified weights:

Images  (5)

Linear interpolation between pixels of an image and a color:

Linear interpolation of an image and a color at a specific value:

Linear interpolation of two images:

Blend of 3D images:

Blend images and their alpha channels:

Generalizations & Extensions  (1)

Different colors can be given at the single position to generate discontinuities:

Applications  (1)

Use Blend to construct a ColorFunction from base colors:

Properties & Relations  (7)

The weights are always normalized, so that the sum becomes 1:

The position values are always sorted:

When colors are specified using the same color space, that space is used for interpolation:

When colors are specified using different color spaces, interpolation happens in the RGB space:

Lighter is a special case of Blend:

Darker is a special case of Blend:

ColorData contains a large number of predefined Blend colors called "Gradients":

Gradients can be called by their names only:

Polygon supports equal-weight blending of VertexColors:

Possible Issues  (2)

Values outside of the 0, 1 range will be clipped:

In plot functions, use ColorFunctionScaling to control global scaling of variables:

With multiple colors for the same xi, the first one is used in (xi-1,xi) interval and the last one in [xi,xi+1):

Interactive Examples  (4)

Continuous blend between two images:

Linear interpolation of two images with different dimensions:

Blend of multiple images while going through a white background between each two images:

Interactive representation of the linear interpolation of multiple colors:

Neat Examples  (2)

Use Blend with plots to generate synthesized textures:

Simulated colors of stars:

Introduced in 2007
 (6.0)
 |
Updated in 2014
 (10.0)