Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created April 23, 2014 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwok91/0fe776f8ebed1d2e739c to your computer and use it in GitHub Desktop.
Save jkwok91/0fe776f8ebed1d2e739c to your computer and use it in GitHub Desktop.
triangle practice
/*
generic triangles by reuben thomas:
http://www.functor.co/post/30584901916/look-at-how-generic-these-generic-triangles-i
which i will now copy as practice
*/
//horribly named variables
//side, height, color of border, angle for periodic function
float s, h, c, a;
void setup() {
size(300, 300);
frameRate(3);
strokeWeight(5);
a = 0;
c = 0;
s = 25;
h = s*sqrt(3)/2;
//noLoop();
}
void draw() {
background(0);
c = abs(sin(a)*255);
stroke(c);
for (float i = 0; i < height+h; i+=h) {
float start = (i%(h*2) == 0) ? 0 : -s/2;
for (float j = start; j < width+s; j+=s) {
fill((random(50,255)+c)%255);
triangle(j, i, j+s/2, i+h, j+s, i);
fill((random(50,255)+c)%255);
triangle(j, i, j-s/2, i+h, j+s/2, i+h);
}
}
a = (a+0.1)%TWO_PI;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment