首页 > 文档 > green()绿色值
2017
08-08

green()绿色值

Name

green()绿色值

   

Examples

green()绿色值 - 第1张  | Processing编程艺术green()绿色值 - 第2张  | Processing编程艺术green()绿色值 - 第3张  | Processing编程艺术

color c = color(20, 75, 200); // Define color ‘c’

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

rect(15, 20, 35, 60); // Draw left rectangle

 

float greenValue = green(c); // Get green in ‘c’

println(greenValue); // Print “75.0”

fill(0, greenValue, 0); // Use ‘greenValue’ in new fill

rect(50, 20, 35, 60); // Draw right rectangle

Description

Extracts the green value from a color, scaled to match current colorMode(). The value is always returned as a float, so be careful not to assign it to an int value.

The green() function is easy to use and understand, but it is slower than a technique called bit shifting. When working in colorMode(RGB, 255), you can acheive the same results as green() but with greater speed by using the right shift operator (>>) with a bit mask. For example, the following two lines of code are equivalent means of getting the green value of the color value c:

从颜色中提取绿色值, 缩放以匹配当前 colorMode ()。该值始终作为浮点返回, 因此请注意不要将其赋给一个 int 值。

 

绿色 () 函数易于使用和理解, 但它比称为位移位的技术慢。当工作在 colorMode (RGB, 255), 你可以获得相同的结果, 绿色 (), 但以更大的速度通过使用右移位操作符 (>>) 与位掩码。例如, 以下两行代码是获取颜色值 c 的绿色值的等效方法:

 

float r1 = green(c); // Simpler, but slower to calculate

float r2 = c >> 8 & 0xFF; // Very fast to calculate

Syntax

green(rgb)

Parameters

rgb

int: any value of the color datatype

 

颜色数据类型的任何值

Returns

float

Related

red()
blue()
alpha()
hue()
saturation()
brightness()
>> (right shift)



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

留下一个回复

你的email不会被公开。