Triangle Strip
Example by Ira Greenberg. Generate a closed ring using the vertex() function and beginShape(TRIANGLE_STRIP) mode. The outsideRadius and insideRadius variables control ring's radii respectively.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
let x;
let y;
let outsideRadius = 150;
let insideRadius = 100;
function setup() {
createCanvas(720, 400);
background(204);
x = width / 2;
y = height / 2;
}
function draw() {
background(204);
let numPoints = int(map(mouseX, 0, width, 6, 60));
let angle = 0;
let angleStep = 180.0 / numPoints;
beginShape(TRIANGLE_STRIP);
for (let i = 0; i <= numPoints; i++) {
let px = x + cos(radians(angle)) * outsideRadius;
let py = y + sin(radians(angle)) * outsideRadius;
angle += angleStep;
vertex(px, py);
px = x + cos(radians(angle)) * insideRadius;
py = y + sin(radians(angle)) * insideRadius;
vertex(px, py);
angle += angleStep;
}
endShape();
}