Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2013 11:59
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 anonymous/6622369 to your computer and use it in GitHub Desktop.
Save anonymous/6622369 to your computer and use it in GitHub Desktop.
processing.org code for the cover of http://8tracks.com/danielrt/29
int i, j, k; //loops
int[] hexCenter=new int[2]; //center of current hexagon
int[][] hexVertices=new int[6][2]; //vertices of current hexagon
int start; //random starting vertex
int hexWidth; //width of the closed hexagon
PImage img; //the raster image
int gray; //color of current pixel
void setup() {
size(1080, 1080);
background(255, 232, 0); //yellow
img=loadImage("portada_29.png"); //45x45px raster image
loadPixels();
updatePixels();
strokeWeight(2);
strokeCap(ROUND);
//change the text values in both for... loops if the image size is different
for (j=0; j<45; j++) {
for (i=0; i<45; i++) {
gray=5-round(red(img.pixels[i+j*img.width])/51.2);
hexCenter[0]=i*24+12; //x-coordinate
hexCenter[1]=j*24+12+(i%2)*12; //y-coordinate
hexVertices[0][0]=hexCenter[0]-8;
hexVertices[0][1]=hexCenter[1]-12;
hexVertices[1][0]=hexCenter[0]+8;
hexVertices[1][1]=hexCenter[1]-12;
hexVertices[2][0]=hexCenter[0]+16;
hexVertices[2][1]=hexCenter[1];
hexVertices[3][0]=hexCenter[0]+8;
hexVertices[3][1]=hexCenter[1]+12;
hexVertices[4][0]=hexCenter[0]-8;
hexVertices[4][1]=hexCenter[1]+12;
hexVertices[5][0]=hexCenter[0]-16;
hexVertices[5][1]=hexCenter[1];
start=round(random(5)); //rotation of hexagon
hexWidth=round(random((gray+1)%5, 5)); //width of the closed hexagon
strokeWeight(2+gray);
stroke(round(185+random(14*gray)), 33, 92); //color variation
for (k=0; k<hexWidth; k++) { //hexagon perimeter
line(
hexVertices[(start+k)%6][0],
hexVertices[(start+k)%6][1],
hexVertices[(start+k+1)%6][0],
hexVertices[(start+k+1)%6][1]
);
}
line( //initial radial line
hexCenter[0],
hexCenter[1],
hexVertices[start][0],
hexVertices[start][1]
);
line( //final radial line
hexCenter[0],
hexCenter[1],
hexVertices[(start+hexWidth)%6][0],
hexVertices[(start+hexWidth)%6][1]
);
}
}
//uncomment the next line to save
//save("portada_29_final.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment