📜  p5.js | endContour()函数

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

p5.js | endContour()函数

p5.js 中的endContour()函数用于在使用beginContour()函数创建计数时停止记录顶点。这些函数用于从另一个形状中删除一个形状的一部分。

内部形状的顶点必须以与外部形状相反的方向定义。如果外部形状的顶点按顺时针方向定义,则内部形状必须按逆时针方向定义。然后使用此函数停止内部形状的记录。

此函数只能在beginShape()endShape()函数内部使用。 translate()rotate()scale()等转换不适用于形状和轮廓。

句法:

endContour()

参数:此函数不接受任何参数。

下面的程序说明了 p5.js 中的endContour()函数:

例子:

function setup() {
  createCanvas(400, 300);
  textSize(16);
}
  
function draw() {
  clear();
  background("green");
  text("The inside of the letter is cut out"+
       " using a countour", 10, 20);
  
  // Starting the shape
  // using beginShape()
  beginShape();
  
  // Specifying all the vertices
  // of the exterior shape
  vertex(40, 240);
  vertex(100, 50);
  vertex(130, 50);
  vertex(200, 240);
  vertex(160, 240);
  vertex(140, 160);
  vertex(100, 160);
  vertex(75, 240);
  
  // Starting a contour
  beginContour();
  
  // Specifying all the vertices
  // of the interior shape
  // in counter-clockwise order
  vertex(130, 135);
  vertex(115, 90);
  vertex(105, 135);
  
  // Ending the contour
  // using endContour()
  endContour();
  
  // Ending the shape
  endShape(CLOSE);
}

输出:
endContour-字母-A

在线编辑器: https://editor.p5js.org/
环境设置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

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