首页 > 文档 > color颜色
2017
07-15

color颜色

Name

color颜色

   

Examples

color颜色 - 第1张  | Processing编程艺术

color c1 = color(204, 153, 0);

color c2 = #FFCC00;

noStroke();

fill(c1);

rect(0, 0, 25, 100);

fill(c2);

rect(25, 0, 25, 100);

color c3 = get(10, 50);

fill(c3);

rect(50, 0, 50, 100);

Description

描述

Datatype for storing color values. Colors may be assigned with get() and color() or they may be specified directly using hexadecimal notation such as #FFCC00 or 0xFFFFCCOO

Using print() or println() on a color will produce strange results (usually negative numbers) because of the way colors are stored in memory. A better technique is to use the hex() function to format the color data, or use the red()green(), and blue() functions to get individual values and print those. The hue()saturation(), and brightness() functions work in a similar fashion. To extract red, green, and blue values more quickly (for instance when analyzing an image or a frame of video), use bit shifting

Values can also be created using web color notation. For example: color c = #006699 

Web color notation only works for opaque colors. To define a color with an alpha value, you can either use color() or hexadecimal notation. For hex notation, prefix the values with 0x, for instance color c = 0xCC006699. In that example, CC (the hex value of 204) is the alpha value, and the remainder is identical to a web color. Note that in hexadecimal notation, the alpha value appears in the first position. (The alpha value appears last when used within color()fill(), and stroke().) The following is an equivalent way of writing the preceding example, but using color() and specifying the alpha value as its second parameter: color c = color(#006699, 191) 

From a technical standpoint, colors are 32 bits of information ordered as AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB where the A’s contain the alpha value, the R’s are the red value, G’s are green, and B’s are blue. Each component is 8 bits (a number between 0 and 255). These values can be manipulated with bit shifting.

用于存储颜色值的数据类型。颜色可以通过获取” () 颜色” () 来分配, 也可以使用十六进制符号 ( # FFCC00 0xFFFFCCOO) 直接指定。

 

对颜色使用 print () println () 会产生奇怪的结果 (通常为负数), 因为颜色存储在内存中的方式。更好的方法是使用十六进制 () 函数来设置颜色数据的格式, 或者使用红色 ()、绿色 () 和蓝色 () 函数来获取单个值并打印它们。色调 ()、饱和度 () 和亮度 () 函数的工作方式类似。要更快地提取红色、绿色和蓝色值 (例如, 在分析图像或视频帧时), 请使用位移位。

 

也可以使用 web 颜色表示法创建值。例如: 颜色 c = # 006699

 

web 颜色表示法只适用于不透明颜色。若要定义具有 alpha 值的颜色, 可以使用颜色 () 或十六进制表示法。对于十六进制表示法, 将值前缀为 0x, 例如颜色 c = 0xCC006699。在该示例中, cc (十六进制值 204) alpha , 其余部分与 web 颜色相同。请注意, 在十六进制表示法中, alpha 值出现在第一个位置。(当在颜色 ()、填充 () 和描边 () 中使用时, alpha 值显示为最后。下面是编写上述示例的等效方法, 但使用颜色 () 并将 alpha 值指定为其第二个参数: 颜色 c = 颜色 (# 006699, 191)

 

从技术角度看, 颜色是32位的信息排序为 AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB, 其中 a 的包含 alpha , r 的是红色值, g 是绿色, b 是蓝色。每个组件都是8 (介于0255之间的数字)。这些值可以用位移位操作。



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

留下一个回复

你的email不会被公开。