p5.js中的setRed()函数用于在RGB颜色模式下设置红色值。它设置RGB格式的第一个值。
用法:
setRed(red)
参数:该函数接受上述和以下描述的单个参数:
- red:此参数存储新的红色值。
 
以下程序说明了p5.js中的setRed()函数:
示例-1:这个例子使用setRed()函数用于设置RGB颜色格式的红色值。
/* declare a variable to  
 store the value of color*/
let backgroundColor; 
  
function setup() { 
    /* initialise the variable 
     with RGB color format*/
    backgroundColor = color(0, 50, 150); 
} 
  
function draw() { 
    // Create Canvas of a given size 
  
    createCanvas(500, 500); 
  
    // Use of setRed function 
    backgroundColor.setRed( 
      0 + 128 * cos(millis() / 1000)); 
  
    /* Pass the initialized  
      variable to background function*/
    background(backgroundColor); 
  
    // Set text size 
    textSize(30); 
  
    // Set text color 
    fill("white"); 
  
    // set text 
    text("GeeksForGeeks", 125, 125); 
  
}输出:

示例2:本示例使用setRed()函数设置RGB颜色格式的红色值。
/* declare a variable to 
store the value of color*/
let backgroundColor; 
  
function setup() { 
    /* initialise the variable 
    with RGB color format*/
    backgroundColor = color(0, 0, 0); 
} 
  
function draw() { 
    // Create Canvas of a given size 
  
    createCanvas(540, 500); 
  
    /* Use of setRed function  
    and initialise it to maximum*/
    backgroundColor.setRed(255); 
  
    /* Pass the initialised 
    variable to background function*/
    background(backgroundColor); 
  
    // Set text size 
    textSize(30); 
  
    // Set text color 
    fill("white"); 
  
    // set text 
    text("GeeksForGeeks\n ", 135, 125); 
    text( 
      "A Computer Science Portal For Geeks", 
      10, 155); 
  
}输出:

参考:https://p5js.org/reference/#/p5.Color/setRed
相关用法
- PHP pos()用法及代码示例
 - p5.js sin()用法及代码示例
 - p5.js tan()用法及代码示例
 - d3.js d3.hsl()用法及代码示例
 - p5.js cos()用法及代码示例
 - PHP key()用法及代码示例
 - p5.js log()用法及代码示例
 - p5.js day()用法及代码示例
 - PHP each()用法及代码示例
 - p5.js second()用法及代码示例
 - CSS rgb()用法及代码示例
 - PHP each()用法及代码示例
 
注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 p5.js | setRed() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
