用于绘制一个三角形。
三角形有三条边,由三个点定义。前两个参数用来设定三角形的第一个点:(x1, y1)
。中间的两个参数设定第二个点:(x2, y2)
。后两个参数设定第三个点:(x3, y3)
。
示例
function setup() {
createCanvas(100, 100);
background(200);
triangle(30, 75, 58, 20, 86, 75);
describe('A white triangle with a black outline on a gray canvas.');
}
function setup() {
createCanvas(100, 100, WEBGL);
background(200);
triangle(-20, 25, 8, -30, 36, 25);
describe('A white triangle with a black outline on a gray canvas.');
}
function setup() {
createCanvas(100, 100, WEBGL);
describe('A white triangle spins around on a gray canvas.');
}
function draw() {
background(200);
// Rotate around the y-axis.
rotateY(frameCount * 0.01);
// Draw the triangle.
triangle(-20, 25, 8, -30, 36, 25);
}
语法
triangle(x1, y1, x2, y2, x3, y3)
参数
x1
数字:
第一个点的 x 轴坐标。
y1
数字:
第一个点的 y 轴坐标。
x2
数字:
第二个点的 x 轴坐标。
y2
数字:
第二个点的 y 轴坐标。
x3
数字:
第三个点的 x 轴坐标。
y3
数字:
第三个点的 y 轴坐标。
Notice any errors or typos? Please let us know. Please feel free to edit src/core/shape/2d_primitives.js and open a pull request!