r1 - 23 Dec 2007 - 18:37:16 - WhaleForestYou are here: TWiki >  Processing Web > ProcessingHandbookChinese > Shape1CoordinatesPrimitivesGrayValues

Gray values 灰度

以上所有例子的视觉窗口都使用了默认的浅灰色背景,黑色线条,白色填充。想要改变这些设置就必须在程序中声明,使用background() 函数可以在0-255范围内设置视觉窗口的灰度,数字255代表黑色数字0代表白色,在这个范围内更改数字就可以得到想要的灰度。默认情况下背景颜色是204(浅灰色):

background(0); 
  
2-25

background(124); 
  
2-26

background(230); 
  
2-27

P32 fill()函数用来控制图形的填充色,stroke()用来控制图形外框颜色。 默认情况下填充数值为255(白色),外框颜色为0(黑色)。

rect(10, 10, 50, 50); 
  fill(204);  // 浅灰
  rect(20, 20, 50, 50); 
  fill(153);  // 中灰 
  rect(30, 30, 50, 50); 
  fill(102);  // 暗灰 
  rect(40, 40, 50, 50); 
  
2-28

background(0); 
  rect(10, 10, 50, 50); 
  stroke(102); // 暗灰 
  rect(20, 20, 50, 50); 
  stroke(153); // 中灰 
  rect(30, 30, 50, 50); 
  stroke(204); // 浅灰 
  rect(40, 40, 50, 50);  
  
2-29

默认情况下所有图形的填充色和外框色都一样, 重新设定fill()函数和stroke()函数的数值可以改变这种情况。

fill(255);  // 白色
  rect(10, 10, 50, 50); 
  rect(20, 20, 50, 50); 
  rect(30, 30, 50, 50); 
  fill(0);  // 黑色 
  rect(40, 40, 50, 50);   
  
2-30

fill()函数和stroke()函数的第二个参数用来设置透明度,参数值为255时图形完全不透明,设置为0时完全透明:

background(0); 
  fill(255, 220); 
  rect(15, 15, 50, 50); 
  rect(35, 35, 50, 50); 
  fill(0);  
  
2-31

fill(0); 
  rect(0, 40, 100, 20); 
  fill(255, 51);   // 高透明度 
  rect(0, 20, 33, 60); 
  fill(255, 127);  // 中透明度 
  rect(33, 20, 33, 60); 
  fill(255, 204);  // 低透明度 
  rect(66, 20, 33, 60); 
  
2-32

P33 填充色和外框色可以被禁用,这时就要分别用到noFill()函数和noStroke()函数,如果同时使用这两个函数,视觉窗口中将会看不到任何图形。

rect(10, 10, 50, 50); 
  noFill();  // 禁用填充 
  rect(20, 20, 50, 50); 
  rect(30, 30, 50, 50); 
  
2-33

rect(20, 15, 20, 70); 
  noStroke();  // 禁用外框
  rect(50, 15, 20, 70); 
  rect(80, 15, 20, 70);
  
2-34

色彩填充和外框数值设定的详细讲解参看章节 Color1(p.85)

-- WhaleForest - 23 Dec 2007

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback