<< Chapter < Page | Chapter >> Page > |
Colors are represented by a triple of numbers, each giving the
intensity of the primary colorsRed, Green, and Blue. Each
number can be an unsigned integer, thus taking values between0 and 255, or be expressed as a floating point number between
and
. With even larger flexibility, the
model, type, and range of colors can be set with the function
colorMode()
. The RGB model is additive.
Colors are represented by a triple of numbers, the first number giving the Hue, the second giving Saturation, and thethird giving the Brightness.
It is a byte used to blend and interpolate between images, for
example to render transparency. It can be obtained, from avariable of type
color
, with the method
alpha()
. The alpha channel can be manipulated
with the method
blend()
of the class
PImage
.
size(400,300);PImage b = loadImage("gondoliers.jpg");
PImage a = loadImage("gondoliers.jpg");float ramp = 0;
for (int j = 0; j<b.height; j++)
for (int i = 0; i<b.width; i++) {
b.set(i, j, b.get(i,j) +color(0,0,0, 255 - (int)((1-ramp)*255)) );
ramp = ramp + 1/(float)(b.width * b.height);}
a.blend(b, 0, 0, b.width, b.height,80, 10, 450, 250, BLEND);
image(a, 0, 0, 400, 300); |
In Processing, it is possible to assign a color to a variable of type
color
by means of the function
color()
, and the model can be previously set with
colorMode()
. The functions
red()
,
green()
,
blue()
,
hue()
,
saturation()
, and
brightness()
allow to move from one model to the other.
colorMode(RGB);
color c1 = color(102, 30,29);colorMode(HSB);
color c2 = color(hue(c1), saturation(c1), brightness(c1));colorMode(RGB);
color c3 = color(red(c2), green(c2), blue(c2));// the variables c1, c2, and c3 contain the coding of the same color
Notification Switch
Would you like to follow the 'Media processing in processing' conversation and receive update notifications?