首页 > 文档 > color()颜色类型
2017
08-08

color()颜色类型

Name color()颜色类型
Examples color()颜色类型 - 第1张  | Processing编程艺术color()颜色类型 - 第2张  | Processing编程艺术color()颜色类型 - 第3张  | Processing编程艺术

color c = color(255, 204, 0); // Define color ‘c’

fill(c); // Use color variable ‘c’ as fill color

noStroke(); // Don’t draw a stroke around shapes

rect(30, 20, 55, 55); // Draw rectangle

color()颜色类型 - 第4张  | Processing编程艺术color()颜色类型 - 第5张  | Processing编程艺术color()颜色类型 - 第6张  | Processing编程艺术

color c = color(255, 204, 0); // Define color ‘c’

fill(c); // Use color variable ‘c’ as fill color

noStroke(); // Don’t draw a stroke around shapes

ellipse(25, 25, 80, 80); // Draw left circle

// Using only one value with color()

// generates a grayscale value.

c = color(65); // Update ‘c’ with grayscale value

fill(c); // Use updated ‘c’ as fill color

ellipse(75, 75, 80, 80); // Draw right circle

color()颜色类型 - 第7张  | Processing编程艺术color()颜色类型 - 第8张  | Processing编程艺术color()颜色类型 - 第9张  | Processing编程艺术

color c; // Declare color ‘c’

noStroke(); // Don’t draw a stroke around shapes

// If no colorMode is specified, then the

// default of RGB with scale of 0-255 is used.

c = color(50, 55, 100); // Create a color for ‘c’

fill(c); // Use color variable ‘c’ as fill color

rect(0, 10, 45, 80); // Draw left rect

colorMode(HSB, 100); // Use HSB with scale of 0-100

c = color(50, 55, 100); // Update ‘c’ with new color

fill(c); // Use updated ‘c’ as fill color

rect(55, 10, 45, 80); // Draw right rect

Description Creates colors for storing in variables of the color datatype. The parameters are interpreted as RGB or HSB values depending on the current colorMode(). The default mode is RGB values from 0 to 255 and, therefore, color(255, 204, 0) will return a bright yellow color (see the first example above).

Note that if only one value is provided to color(), it will be interpreted as a grayscale value. Add a second value, and it will be used for alpha transparency. When three values are specified, they are interpreted as either RGB or HSB values. Adding a fourth value applies alpha transparency.

Note that when using hexadecimal notation, it is not necessary to use color(), as in: color c = #006699

More about how colors are stored can be found in the reference for the color datatype.

创建用于存储在颜色数据类型变量中的颜色。根据当前的 colorMode (), 参数被解释为 RGB HSB 值。默认模式是 RGB 值从0 255, 因此, 颜色 (2552040) 将返回明亮的黄色 (参见上面的第一个示例)

请注意, 如果只为颜色 () 提供一个值, 则将其解释为灰度值。添加第二个值, 它将用于 alpha 透明度。当指定三值时, 它们被解释为 RGB HSB 值。添加第四值将应用 alpha 透明度。

请注意, 在使用十六进制表示法时, 不需要使用颜色 (), 如中所示: 颜色 c = # 006699

有关如何存储颜色的详细信息, 请参阅颜色数据类型的参考。

Syntax color(gray)

color(gray, alpha)

color(v1, v2, v3)

color(v1, v2, v3, alpha)

Parameters
gray int: number specifying value between white and black

指定介于白色和黑色之间的数值

alpha float, or int: relative to current color range

透明度

v1 float, or int: red or hue values relative to the current color range

对于当前颜色范围的红色或色相值

v2 float, or int: green or saturation values relative to the current color range

对于当前颜色范围的绿色或色相值

v3 float, or int: blue or brightness values relative to the current color range

对于当前颜色范围的蓝色或色相值

Returns int
Related colorMode()


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

留下一个回复

你的email不会被公开。