p5.js中的shorten()函數用於將給定數組的元素數量減少一。
用法:
shorten(Array)
參數:此函數接受參數Array,其元素將縮短一。
返回值:它返回縮短的數組。
以下示例程序旨在說明p5.js中的shorten()函數。
示例1:
function setup() {
// Creating Canvas size
createCanvas(500, 90);
}
function draw() {
// Set the background color
background(220);
// Initializing the arrays
let Array1 = ['IT', 'CSE', 'ECE'];
// Calling to shorten() function.
let Array2 = shorten(Array1);
// Set the size of text
textSize(16);
// Set the text color
fill(color('red'));
// Getting new shortened array
text("Shortened array is : " + Array2, 50, 30);
}
輸出:
示例2:
function setup() {
// Creating Canvas size
createCanvas(500, 90);
}
function draw() {
// Set the background color
background(220);
// Calling to shorten() function on an array
// Taken as the parameter
let Array = shorten(['Ram', 'Shayam', 'Geeta', 'Anita']);
// Set the size of text
textSize(16);
// Set the text color
fill(color('red'));
// Getting new shortened array
text("Shortened array is : " + Array, 50, 30);
}
輸出:
參考: https://p5js.org/reference/#/p5/shorten
相關用法
- d3.js d3.max()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- CSS hsl()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP each()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 p5.js | shorten() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。