首页 > 文档 > colorMode()颜色模式
2017
08-08

colorMode()颜色模式

Name

colorMode()颜色模式

   

Examples

colorMode()颜色模式 - 第1张  | Processing编程艺术colorMode()颜色模式 - 第2张  | Processing编程艺术colorMode()颜色模式 - 第3张  | Processing编程艺术

noStroke();

colorMode(RGB, 100);

for (int i = 0; i < 100; i++) {

for (int j = 0; j < 100; j++) {

stroke(i, j, 0);

point(i, j);

}

}

colorMode()颜色模式 - 第4张  | Processing编程艺术colorMode()颜色模式 - 第5张  | Processing编程艺术colorMode()颜色模式 - 第6张  | Processing编程艺术

noStroke();

colorMode(HSB, 100);

for (int i = 0; i < 100; i++) {

for (int j = 0; j < 100; j++) {

stroke(i, j, 100);

point(i, j);

}

}

colorMode()颜色模式 - 第7张  | Processing编程艺术colorMode()颜色模式 - 第8张  | Processing编程艺术colorMode()颜色模式 - 第9张  | Processing编程艺术

// If the color is defined here, it won’t be

// affected by the colorMode() in setup().

// Instead, just declare the variable here and

// assign the value after the colorMode() in setup()

//color bg = color(180, 50, 50); // No

color bg; // Yes, but assign it in setup()

 

void setup() {

size(100, 100);

colorMode(HSB, 360, 100, 100);

bg = color(180, 50, 50);

}

 

void draw() {

background(bg);    

}

Description

Changes the way Processing interprets color data. By default, the parameters for fill()stroke()background(), and color() are defined by values between 0 and 255 using the RGB color model. The colorMode() function is used to change the numerical range used for specifying colors and to switch color systems. For example, calling colorMode(RGB, 1.0) will specify that values are specified between 0 and 1. The limits for defining colors are altered by setting the parameters maxmax1max2max3, and maxA

After changing the range of values for colors with code like colorMode(HSB, 360, 100, 100), those ranges remain in use until they are explicitly changed again. For example, after running colorMode(HSB, 360, 100, 100) and then changing back to colorMode(RGB), the range for R will be 0 to 360 and the range for G and B will be 0 to 100. To avoid this, be explicit about the ranges when changing the color mode. For instance, instead of colorMode(RGB), write colorMode(RGB, 255, 255, 255).

更改处理解释颜色数据的方式。默认情况下, 填充 ()、描边 ()、背景 () 和颜色 () 的参数是使用 RGB 颜色模型在0255之间的值定义的。colorMode () 函数用于更改用于指定颜色和切换颜色系统的数值范围。例如, 调用 colorMode (RGB, 1.0) 将指定在01之间指定值。定义颜色的限制通过设置参数 maxmax1max2max3 maxA 来改变。

 

在更改颜色值的范围 ( colorMode (HSB360100100) 之后, 这些范围将一直使用, 直到它们再次显式更改。例如, 在运行 colorMode (HSB360100100) 之后, 再更改回 colorMode (RGB), R 的范围将为0 360, G B 的范围将为0100。若要避免这种变化, 请在更改颜色模式时明确有关范围。例如, 而不是 colorMode (rgb), colorMode (rgb, 255, 255, 255)

Syntax

colorMode(mode)

colorMode(mode, max)

colorMode(mode, max1, max2, max3)

colorMode(mode, max1, max2, max3, maxA)

Parameters

mode

int: Either RGB or HSB, corresponding to Red/Green/Blue and Hue/Saturation/Brightness

RGB HSB, 对应于红色/绿色/蓝色和色相/饱和度/亮度

max

float: range for all color elements

所有颜色元素的范围

max1

float: range for the red or hue depending on the current color mode

红色或色相的范围, 取决于当前的颜色模式

max2

float: range for the green or saturation depending on the current color mode

根据当前颜色模式, 绿色或饱和度的范围

max3

float: range for the blue or brightness depending on the current color mode

蓝色或亮度范围 (根据当前颜色模式而定)

maxA

float: range for the alpha

透明度范围

Returns

void

Related

background()
fill()
stroke()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。