Skip to content

Instantly share code, notes, and snippets.

@davidfoerster
Created April 9, 2015 14:34
Show Gist options
  • Save davidfoerster/31dd826f69f30cd9b03a to your computer and use it in GitHub Desktop.
Save davidfoerster/31dd826f69f30cd9b03a to your computer and use it in GitHub Desktop.
triangle_strip.pde
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 angleStep = PI / numPoints;
beginShape(TRIANGLE_STRIP);
for (int i = 0; i <= numPoints; i++)
{
float angle = angleStep * (i * 2);
float px = x + cos(angle) * outsideRadius;
float py = y + sin(angle) * outsideRadius;
vertex(px, py);
angle = angleStep * (i * 2 + 1);
px = x + cos(angle) * insideRadius;
py = y + sin(angle) * insideRadius;
vertex(px, py);
}
endShape();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment