p5.js | strokeWeight()函数
p5.js 中的strokeWeight()函数用于设置线条、点和形状周围边框的笔触宽度。笔画粗细是使用像素设置的。
句法:
strokeWidth(weight)
参数:此函数接受单个参数权重,它存储笔画的权重(以像素为单位)。
下面的程序说明了 p5.js 中的 strokeWeight()函数:
示例 1:本示例使用 strokeWeight()函数设置描边的宽度。
function setup() {
// Create Canvas of given size
createCanvas(380, 170);
}
function draw() {
// Set the background color
background(220);
// Set the stroke width
strokeWeight(20);
// Set the filled color
fill('green');
// Draw the circle
circle(60, 60, 34);
// Set the text size
textSize(20);
// Set the text to print
text("GeeksForGeeks", 120, 70);
}
输出:
示例 2:本示例使用 strokeWeight()函数来设置笔画的宽度。
function setup() {
// Create Canvas of given size
createCanvas(380, 170);
}
function draw() {
// Set the background color
background(220);
// Set the stroke clor
stroke('orange');
// Set the stroke width to 10
strokeWeight(10); // Orange
// Draw a line
line(20, 70, 80, 70);
// Set the stroke color
stroke('white');
// Set the stroke width to 8
strokeWeight(8); // White
// Draw a line
line(20, 90, 80, 90);
// Set stroke color
stroke('green');
// Set the stroke width to 6
strokeWeight(6); // Green
// Draw a line
line(20, 110, 80, 110);
}
输出:
参考: https://p5js.org/reference/#/p5/strokeWeight