noiseSeed()函數用於設置noise()函數的種子值。默認情況下,noise()函數返回一個數字,即semi-random,這意味著噪聲值僅在程序運行之前才對坐標相同。下次運行該程序將產生不同的值。
通過在程序中設置一個不變的種子值,可以使這些噪聲值恒定,以便每次運行程序時都返回相同的值。
用法:
noiseSeed( seed )
參數:該函數接受如上所述和以下描述的單個參數:
- seed:該參數保存一個代表種子值的數字。
返回值:該函數不返回任何值。
下麵的示例說明了p5.js中的noiseSeed()函數:
例:
let x_coordinate = 0.0;
let plot_y = 0.0;
function setup() {
createCanvas(400, 200);
}
function draw() {
// Specifying a noise seed value
noiseSeed(100);
if (x_coordinate < 10) {
// Get noise with x coordinate
x_noise = noise(x_coordinate);
// Output the noise along with
// its corresponding coordinate
coord_text = "Noise for x coordinate "
+ x_coordinate + " is " + x_noise;
text(coord_text, 10, plot_y);
// Increment the x coordinate
x_coordinate++;
// Increase the y coordinate
// for plotting
plot_y = plot_y + 15;
}
}
輸出:每次運行程序時,這些值都是常數。
- 首次運行該程序:
- 第二次運行該程序:
參考: https://p5js.org/reference/#/p5/noiseSeed
相關用法
- CSS url()用法及代碼示例
- p5.js second()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP each()用法及代碼示例
- PHP next()用法及代碼示例
- p5.js pow()用法及代碼示例
- PHP pow( )用法及代碼示例
- CSS var()用法及代碼示例
- p5.js day()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js hue()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | noiseSeed() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。