Skip to content

Instantly share code, notes, and snippets.

Created October 1, 2013 23:07
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/6786622 to your computer and use it in GitHub Desktop.
Save anonymous/6786622 to your computer and use it in GitHub Desktop.
Processing.org code for the cover of the playlist at http://8tracks.com/danielrt/30
int i, j, k; //loops
int r; //third vertix of background triangles
color[] c={
color(234, 38, 92), //red
color(5, 130, 204), //blue
color(144, 204, 0), //green
color(254, 183, 0) //orange
};
PImage img; //the raster image
int gray; //color of current pixel
PGraphics bg; //background image
PImage px; //"pieces" of the background
void setup() {
size(1200, 1200);
background(255);
img=loadImage("portada_30.png"); //75x75px raster image
loadPixels();
updatePixels();
bg=createGraphics(1200, 1200); //inizialiting background...
bg.beginDraw();
bg.background(255);
bg.stroke(0, 127);
bg.strokeWeight(24);
for (i=0; i<11; i++) { //filling the background with colors
bg.fill(c[round(random(3))], round(random(127)));
r=round(random(1)); //to set the third vertix to the left or the right
bg.triangle(
//upper margin
round(random(2000))-400, // -400<x<1600
round(random(400))*(-1), // -400<y<0
//lower margin
round(random(2000))-400, // -400<x<1600
round(random(400))+1200, // 1200<y<1600
//either left or right margin
round(random(400))*(2*r-1)+1200*r, // {-400<x<0}, {1200<x<1600}
round(random(2000)-400) // -400<y<1600
);
}
bg.endDraw();
//image(bg, 0, 0); //displaying each "piece" of the background
for (j=0; j<75; j++) {
for (i=0; i<75; i++) {
gray=32-round(red(img.pixels[i+j*img.width])/8);
px=bg.get(i*16, j*16, 16, 16);
image(px, i*16+round(random(gray))-16, j*16+round(random(gray))-16);
}
}
//last row and last column are missing...
for (i=0; i<=75; i++) {
px=bg.get(i*16, 1184, 16, 16);
image(px, i*16, 1184);
}
for (j=0; j<=75; j++) {
px=bg.get(1184, j*16, 16, 16);
image(px, 1184, j*16);
}
//uncomment the next line to save
//save("portada_30_final.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment