5. 设置

5.2. 形状填充颜色


fill()

示例:

▶️运行示例代码



function setup(){
  createCanvas(100,100);
  colorMode(HSB);
};

function draw(){
  background('#c0c0c0');
  fill(color(180,100,100,100));
  rect(20,20,60);
};

舞台区显示的画布内容如下:


Description

Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all shapes drawn after the fill command will be filled with the color orange. This color is either specified in terms of the RGB or HSB color depending on the current colorMode(). (The default color space is RGB, with each value in the range from 0 to 255). The alpha range by default is also 0 to 255.

If a single string argument is provided, RGB, RGBA and Hex CSS color strings and all named color strings are supported. In this case, an alpha number value as a second argument is not supported, the RGBA form should be used.

p5.Color object can also be provided to set the fill color.

Syntax

fill(v1, v2, v3, [alpha])
fill(value)
fill(gray, [alpha])
fill(values)
fill(color)

Parameters

  • v1
     
    Number: 

    red or hue value relative to the current color range

  • v2
     
    Number: 

    green or saturation value relative to the current color range

  • v3
     
    Number: 

    blue or brightness value relative to the current color range

  • alpha
     
    Number: (Optional)
  • value
     
    String: 

    a color string

  • gray
     
    Number: 

    a gray value

  • values
     
    Number[]: 

    an array containing the red,green,blue & and alpha components of the color

  • color
     
    p5.Color

    the fill color





Tags: