-
-
Save jkwok91/0fe776f8ebed1d2e739c to your computer and use it in GitHub Desktop.
triangle practice
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
/* | |
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