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 & HelpSyntax Questions › Pixelation Technique
Page Index Toggle Pages: 1
Pixelation Technique (Read 751 times)
Pixelation Technique
Nov 20th, 2007, 2:00am
 
Hi Everyone! I am currenly learning Processing for the first time. I have gone through a few tutorials and read alot of notes. I recently learned the ability to pixelate an image. I have modified the code to make each time i click, the pixelation increases by 10. I was wondering if it is possible for it to reach 155 pixels wide, then when i continue to click, the pixelation will decrease until it reaches 10 pixels again. The outcome i am looking for will be continual clicking blurring then unblurring the picture incrimentally. I have provided the code i have already below.

Thanks for any help anyone can provide.

PImage leftovers;
int detail = 5;
int undetail = 5;

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

void draw(){
 ;
}

void mouseClicked(){
 for ( int i=0; i<width; i+=detail ){
   for ( int j=0; j<height; j+=undetail){
     color c=leftovers.get(i,j);
     fill(c);
     rect(i, j, detail, undetail);
   }
 }
 if (detail < 155){
   detail += 10;
 }
 if (undetail < 155){
   undetail += 10;
}

Re: Pixelation Technique
Reply #1 - Nov 20th, 2007, 8:09am
 
Hi! You could try with an int (say, called blur) taking +1 or -1 value, depending on the value reached by detail. The statement detail += blur*10; either increases the pixelation or decreases it, depending on the blur value.

Code:
PImage leftovers;
final int detailMin = 5;
final int detailMax = 155;
int detail = detailMin;
int blur = 1;

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

void draw(){
}

void mouseClicked(){
for ( int i=0; i<width; i+=detail ){
for ( int j=0; j<height; j+=detail){
color c=leftovers.get(i,j);
fill(c);
rect(i, j, detail, detail);
}
}
if (detail <= detailMin){
detail = detailMin;
blur = 1;
} else if (detail > detailMax) {
detail = detailMax;
blur = -1;
}
detail += blur*10;
}
Page Index Toggle Pages: 1