We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › First Sketch! (Coloursort)
Page Index Toggle Pages: 1
First Sketch! (Coloursort) (Read 404 times)
First Sketch! (Coloursort)
Jan 26th, 2009, 12:40am
 
Hello everybody!

First off, massive props to anyone involved in developing processing, it's an amazing piece of software. I can't believe it took me so long to find it. It's already robbed me of several nights sleep haha.

Anyways, this is my first sketch. I'm sure it's been done before, but I'm still pretty stoked on the result.

Here's the source:

Code:

/* COLOURSORT Joe Whitehouse Jan 25 2009

Converts an image into an array of pixels roughly sorted by colour

s saves the image
- decreases the pixel size
+ increases the pixel size

If pixel size is low, it takes a few seconds to calculate

*/

PImage a;

int s = 4; // default pixel size

//image must be in data folder
String id = "image.jpg";

void setup() {
size(600, 600);
a = loadImage(id);
noStroke();
noLoop();
}

void draw() {
image(a, 0, 0, width, height);
loadPixels();
pixels = sort(pixels);
pixels = reverse(pixels);
updatePixels();
for(int i=0;i<width/s;i++){
for(int j=0;j<height/s;j++){
fill(pixels[j*s*width+i*s]);
rect(i*s,j*s,s,s);
}
}
}

void keyPressed(){
switch(key) {
case 's':
case 'S':
String[] filename = split(id, '.');
saveFrame(filename[0]+".png");
println("Image Saved - "+filename[0]+".png");
break;
case '-':
if(s>1){
s--;
}
redraw();
break;
case '=':
if(s<21){
s++;
}
redraw();
break;
}
}


And here's some example outputs using album art as source images - flickr set

Much love x
Re: First Sketch! (Coloursort)
Reply #1 - Jan 26th, 2009, 10:00am
 
That's an amusing idea, nicely done.
Page Index Toggle Pages: 1