Created
April 9, 2015 14:34
-
-
Save davidfoerster/31dd826f69f30cd9b03a to your computer and use it in GitHub Desktop.
triangle_strip.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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