當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


p5.js specularColor()用法及代碼示例

p5.j​​s中的specularColor()函數用於設置鏡麵高光與鏡麵材質和高光一起使用時的顏色。

此方法通常與specularMaterial()和shininess()函數一起使用以定義鏡麵高光。沒有specularMaterial()函數,該函數將無效。如果不使用此函數,則默認的鏡麵反射高光顏色為白色。

用法:



specularColor( v1, v2, v3 )

OR

specularColor( value )

OR

specularColor( gray )

OR

specularColor( values )

OR

specularColor( color )

參數:此函數接受上述和以下所述的七個參數:

  • v1:它是一個數字,用於確定相對於當前顏色範圍的紅色或色調值。
  • v2:它是一個數字,用於確定相對於當前顏色範圍的綠色或飽和度值。
  • v3:它是一個數字,用於確定相對於當前顏色範圍的藍色或亮度值。
  • value:它是定義鏡麵反射高光顏色的字符串。
  • gray:它是一個數字,用於定義鏡麵反射高光的灰度值。
  • values:它是一組數字,用於定義鏡麵反射高光顏色的紅色,綠色,藍色和alpha分量。
  • color:它是p5.Color,它定義了鏡麵反射高光的顏色。

以下示例說明了p5.js中的specularColor()函數:

例:

let newFont; 
  
function preload() { 
  newFont = loadFont('fonts/Montserrat.otf'); 
} 
  
function setup() { 
  createCanvas(600, 300, WEBGL); 
  textFont(newFont, 18); 
  
  redColorSlider = createSlider(0, 255, 128, 1); 
  redColorSlider.position(20, 50); 
  
  blueColorSlider = createSlider(0, 255, 128, 1); 
  blueColorSlider.position(20, 80); 
} 
  
function draw() { 
  background('green'); 
  text("Move the sliders to change the red and"
    + " blue specular highlights", -285, -125); 
  noStroke(); 
  shininess(15); 
  
  redSpecularIntensity = redColorSlider.value(); 
  blueSpecularIntensity = blueColorSlider.value(); 
  
  specularColor(redSpecularIntensity, 0, 0); 
  pointLight(255, 0, 0, -width / 2, -height / 2, 250); 
  specularColor(0, 0, blueSpecularIntensity); 
  pointLight(0, 0, 255, width / 2, height / 2, 250); 
  
  specularMaterial(250); 
  sphere(100); 
}

輸出:
slider-colors

在線編輯: https://editor.p5js.org/

環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

參考: https://p5js.org/reference/#/p5/specularColor




相關用法


注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | specularColor() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。