📜  p5.js | noTint()函数

📅  最后修改于: 2022-05-13 01:56:31.413000             🧑  作者: Mango

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;
}

输出:
切换无色调

在线编辑器: https://editor.p5js.org/

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

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