 |
 |
 |
 |
Name |
|
blend() |
 |
|
|
Examples |
|
 |
color orange = color(204, 102, 0);
color blue = color(0, 102, 153);
color orangeblueadd = blend(orange, blue, ADD);
background(51);
noStroke();
fill(orange);
rect(14, 20, 20, 60);
fill(orangeblueadd);
rect(40, 20, 20, 60);
fill(blue);
rect(66, 20, 20, 60);
|
 |
 |
background(loadImage("rockies.jpg"));
PImage img = loadImage("degaul.jpg");
image(img, 0, 0);
blend(img, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
|
 |
 |
background(loadImage("rockies.jpg"));
PImage img = loadImage("degaul.jpg");
image(img, 0, 0);
blend(img, 0, 0, 33, 100, 67, 0, 33, 100, SUBTRACT);
|
 |
 |
background(loadImage("rockies.jpg"));
PImage img = loadImage("degaul.jpg");
image(img, 0, 0);
blend(img, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
|
 |
 |
background(loadImage("rockies.jpg"));
PImage img = loadImage("degaul.jpg");
image(img, 0, 0);
blend(img, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
|
 |
|
Description |
|
Blends two color values and copies a single pixel or region of pixels from one image into another (or in itself again) with full alpha channel support. There is a choice of the following modes to blend the source pixels (A) with the ones of pixels in the destination image (B):
BLEND - linear interpolation of colours: C = A*factor + B
ADD - additive blending with white clip: C = min(A*factor + B, 255)
SUBTRACT - subtractive blending with black clip: C = max(B - A*factor, 0)
DARKEST - only the darkest colour succeeds: C = min(A*factor, B)
LIGHTEST - only the lightest colour succeeds: C = max(A*factor, B)
All modes use the alpha information (highest byte) of source image pixels as the blending factor. If the source and destination regions are different sizes, the image will be automatically resized to match the destination size. If the srcImg parameter is not used, the display window is used as the source image.
The imageMode() function changes the way the parameters work. For example, a call to imageMode(CORNERS) will change the width and height parameters to define the x and y values of the opposite corner of the image. |
 |
|
|
Syntax |
|
blend(c1, c2, mode);
blend(sx, sy, dx, dy, mode);
blend(srcImg, sx, sy, dx, dy, mode);
blend(sx1, sy1, swidth, sheight, dx1, dy1, dwidth, dheight, mode);
blend(srcImg, sx1, sy1, swidth, sheight, dx1, dy1, dwidth, dheight, mode);
|
 |
|
|
Parameters |
|
c1 |
|
color: the first color to be blended
|
c2 |
|
color: the second color to be blended
|
mode |
|
Either BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST
|
sx |
|
int: X coordinate of the pixel in source image
|
sy |
|
int: Y coordinate of the pixel in source image
|
dx |
|
int: X coordinate of the pixel in destination image
|
dy |
|
int: Y coordinate of the pixel in destination image
|
srcImg |
|
PImage: a image variable referring to the source image
|
sx1 |
|
int: X coordinate of the source's upper left corner
|
sy1 |
|
int: Y coordinate of the source's upper left corner
|
swidth |
|
int: source image width
|
sheight |
|
int: source image height
|
dx1 |
|
int: X coordinate of the destination's upper left corner
|
dy1 |
|
int: Y coordinate of the destination's upper left corner
|
dwidth |
|
int: destination image width
|
dheight |
|
int: destination image height
|
|
 |
|
|
Returns |
|
None |
 |
|
|
Usage |
|
Web & Application |
 |
|
|
Related |
|
filter() |
|
|