Triangle Strip
Triangle Strip 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.
int x; int y; float outsideRadius = 150; float insideRadius = 100; void setup() { size(640, 360); background(204); x = width/2; y = height/2; } void draw() { background(204); int numPoints = int(map(mouseX, 0, width, 6, 60)); float angle = 0; float angleStep = 180.0/numPoints; beginShape(TRIANGLE_STRIP); for (int i = 0; i <= numPoints; i++) { float px = x + cos(radians(angle)) * outsideRadius; float 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(); }
Functions Used
beginShape()
Using the beginShape() and endShape() functions allow creating more complex forms
Learn More
draw()
Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called
Learn More
endShape()
The endShape() function is the companion to beginShape() and may only be called after beginShape()
Learn More
background()
The background() function sets the color used for the background of the Processing window
Learn More