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.
IndexProgramming Questions & HelpPrograms › Pixel Program
Page Index Toggle Pages: 1
Pixel Program (Read 449 times)
Pixel Program
Nov 21st, 2007, 5:02am
 
Hi, I'm trying to get the detail to move from 5 to 200 in 5 pixel steps but I'm not too sure how to go about it.  Any suggestions?
Here's my program, it's basically an image:

PImage img;
int detail = 5;

void setup() {
size(400, 268);
img = loadImage("blogPhoto023.jpg");
image(img, 0, 0);
}

void draw() {//keeps sketch running so that I can listen for
//the mouse.

;
}
void mouseClicked() {
for ( int i=0; i<width; i+=detail) {
for ( int j=0; j<height; j+=detail) {
color c = img.get(i, j);
fill(c);
rect(i, j, detail, detail);
}
}
detail += 5; //short way of writing: detail = detail + 5;
}
Re: Pixel Program
Reply #1 - Nov 21st, 2007, 9:44am
 
instead of
Code:
color c = img.get(i, j); 



I would calculate the 'average' color of the area you pixelate :
Code:
int avgRed = 0;
int avgGreen = 0;
int avgBlue = 0;

for (int y = 0; y < detail; y++) {
for (int x = 0; x < detail; x++) {
color c = img.get(i+x, j+y);
avgRed += red(c);
avgGreen += green(c);
avgBlue += blue(c);
}
}

avgRed = (int)(avgRed/pow(detail, 2));
avgGreen = (int)(avgGreen/pow(detail, 2));
avgBlue = (int)(avgBlue/pow(detail, 2));
color c = color(avgRed, avgGreen, avgBlue);
Page Index Toggle Pages: 1