Created
March 16, 2013 09:54
-
-
Save anonymous/5175745 to your computer and use it in GitHub Desktop.
processing.org code for http://danielrt.tumblr.com/post/45487703185
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
/** user-defined parameters */ | |
int sides = 8; //sides - 1; at least 4 sides (set to 3) to work | |
int pgRadius = 40; //polygon radius | |
int pgMargin = 40; //polygon margin | |
PFont fnt = createFont("HelveticaNeue", 12); //or any other typeface... | |
color[] c = { //palette | |
color(255), //0 = background (white) | |
color(153), //1 = text (gray) | |
color(15, 170, 247, 255), //2 = symmetry axis color 1 (blue) | |
color(58, 255, 0, 255), //3 = symmetry axis color 2 (green) | |
color(245, 143, 34, 255), //4 = outer color 2 (magenta) | |
color(231, 20, 134, 255) //5 = outer color 2 (orange) | |
}; | |
/** variables for sketch to work */ | |
int i, j, k, l; //used for loops | |
int[][][] pgCenter = new int[sides+1][sides+1][2]; //[column][row][0 = x, 1 = y] | |
int[][] pgVertices = new int[sides+1][2]; //[vertex; 0 = top][0 = x, 1 = y] | |
color[][] gradientC = new color[2][sides+2]; //[axis][step] | |
int[] path = new int[(sides+1)*2+1]; | |
int pathLoops=0; | |
/** the rest */ | |
void setup() { | |
size(pgMargin + (sides+1)*(2*pgRadius+pgMargin), pgMargin + (sides+1)*(2*pgRadius+pgMargin)); | |
background(c[0]); | |
strokeWeight(2); | |
textAlign(CENTER, CENTER); | |
textFont(fnt); | |
path[0]=0; | |
for (i=0; i<=sides+1; i++) { //setting the colors for the other symmetry axis | |
gradientC[1][i] = color( | |
round(((c[4] >> 16) & 0xFF)+((((c[5] >> 16) & 0xFF)-((c[4] >> 16) & 0xFF))/(sides+1))*i), | |
round(((c[4] >> 8) & 0xFF)+((((c[5] >> 8) & 0xFF)-((c[4] >> 8) & 0xFF))/(sides+1))*i), | |
round((c[4] & 0xFF)+(((c[5] & 0xFF)-(c[4] & 0xFF))/(sides+1))*i) | |
); | |
} | |
for (i=0; i<=sides; i++) { //set the coords for the vertices; 0 = top, 1 = next one clockwise | |
pgVertices[i][0] = round(cos(HALF_PI-TWO_PI/(sides+1)*i)*pgRadius); | |
pgVertices[i][1] = round(sin(HALF_PI-TWO_PI/(sides+1)*i)*pgRadius)*-1; | |
for (j=0; j<=sides; j++) { //set the coords of the center of every polygon | |
pgCenter[i][j][0] = pgMargin + pgRadius + i*(pgMargin + 2*pgRadius); | |
pgCenter[i][j][1] = pgMargin + pgRadius + j*(pgMargin + 2*pgRadius); | |
} | |
gradientC[0][i] = color( //setting the colors for one of the symmetry axes | |
round(((c[2] >> 16) & 0xFF)+((((c[3] >> 16) & 0xFF)-((c[2] >> 16) & 0xFF))/(sides))*i), | |
round(((c[2] >> 8) & 0xFF)+((((c[3] >> 8) & 0xFF)-((c[2] >> 8) & 0xFF))/(sides))*i), | |
round((c[2] & 0xFF)+(((c[3] & 0xFF)-(c[2] & 0xFF))/(sides))*i) | |
); | |
} | |
for (i=0; i<=sides; i++) { | |
for (j=0; j<=sides; j++) { | |
stroke(gradientC[1][abs(1+sides-i-j)]); //set the color for the other axis | |
for (k=1; k<=(sides+1)*2; k=k+2) { | |
path[k] = (path[k-1]+i)%(sides+1); | |
path[k+1] = (path[k]+j)%(sides+1); | |
} | |
pathLoops=0; | |
for (k=0; k<(sides+1)*2; k++) { //check how many times does the loop repeat | |
if (path[k]==0 && path[k+1]==path[1]) { | |
pathLoops++; | |
} | |
} | |
for (k=0; k<round((sides+1)*2/pathLoops); k++) { | |
stroke(color( //sets the transparency | |
gradientC[1][abs(1+sides-i-j)] >> 16 & 0xFF, | |
gradientC[1][abs(1+sides-i-j)] >> 8 & 0xFF, | |
gradientC[1][abs(1+sides-i-j)] & 0xFF, | |
93+192*(round((sides+1)*2/pathLoops)-k)/round((sides+1)*2/pathLoops) | |
)); | |
line( //draws the path | |
pgCenter[i][j][0]+pgVertices[path[k]][0], | |
pgCenter[i][j][1]+pgVertices[path[k]][1], | |
pgCenter[i][j][0]+pgVertices[path[k+1]][0], | |
pgCenter[i][j][1]+pgVertices[path[k+1]][1] | |
); | |
} | |
fill(c[1]); | |
text(str(i)+" + "+str(j), pgCenter[i][j][0], pgCenter[i][j][1]+pgVertices[0][1]-12); //legend | |
fill(c[0]); | |
stroke(gradientC[0][abs(i-j)]); //color for the first axis | |
for (k=0; k<=sides; k++) { //set the vertix color, then draw it | |
ellipse(pgCenter[i][j][0]+pgVertices[k][0], pgCenter[i][j][1]+pgVertices[k][1], 6, 6); | |
} | |
} | |
} | |
//uncomment the next line to save | |
//save(str(sides+1)+".png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment