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


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

p5.j​​s中的noErase()函數用於取消erase()函數的效果。它將使fill(),stroke()和blendMode()函數的函數恢複為使用erase()之前的函數。在此函數之後完成的任何繪製都將正常繪製。

用法:

noErase()

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

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

例:



function setup() { 
    createCanvas(600, 400); 
    textSize(20); 
    firstBlockSlider = createSlider(50, 250, 75, 1); 
    firstBlockSlider.position(30, 50); 
   
    secondBlockSlider = createSlider(50, 250, 175, 1); 
    secondBlockSlider.position(30, 120); 
} 
   
function draw() { 
    clear(); 
    fill('black'); 
    text("Move the slider below to change the"
        + " first block's position", 20, 30); 
    text("Move the slider below to change the"
        + " second block's position", 20, 100); 
    text("The black circle demonstrates the"
        + " erase area", 20, 170); 
   
    fill('red'); 
    rect(firstBlockSlider.value(), 200, 50, 100); 
   
    // Start erasing with erase() 
    erase(); 
    circle(150, 250, 100); 
   
    // Stop erasing with noErase() 
    noErase(); 
   
    fill('red'); 
    rect(secondBlockSlider.value(), 200, 50, 100); 
   
    // Circle to illustrate the erase position 
    noFill(); 
    circle(150, 250, 100); 
}

輸出:
demonstrate-noerase

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

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

相關用法


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