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


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

noTint()函數用於刪除以前使用tint()函數應用的圖像的填充值。它將恢複圖像的色彩並以其原始色調顯示它們。

用法:

noTint()

參數:該函數不接受任何參數。


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

範例1:

function preload() { 
  img = loadImage('sample-image.png'); 
} 
  
function setup() { 
  createCanvas(600, 300); 
  textSize(22); 
} 
  
function draw() { 
  clear(); 
  text("Using the tint() function", 20, 20); 
  tint("red"); 
  image(img, 20, 40); 
  
  text("Using the noTint() function", 20, 170); 
  noTint() 
  image(img, 20, 180); 
}

輸出:
tint-noTint-comparison

範例2:

function preload() { 
  img = loadImage('sample-image.png'); 
  disableTint = false; 
} 
  
function setup() { 
  createCanvas(600, 300); 
  textSize(22); 
  
  // Create a button for toggling the 
  // noTint() function 
  removeBtn = createButton("Toggle using noTint"); 
  removeBtn.position(30, 200) 
  removeBtn.mousePressed(removeTint); 
} 
  
function draw() { 
  clear(); 
  text("Click on the button to use the noTint() function", 20, 20); 
  text("Using noTint():" + disableTint, 20, 40); 
  
  // Check if the boolean value is true 
  // to use the noTint() function 
  // in this draw loop 
  if (disableTint) noTint(); 
  
  image(img, 30, 60); 
  
  // Using the tint() function here 
  // would tint the image in the next 
  // draw loop 
  tint("red"); 
} 
  
function removeTint() { 
  // Toggle the use of noTint() 
  disableTint = !disableTint; 
}

輸出:
toggle-noTint

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

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

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



相關用法


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