Drossy
YaBB Newbies
Offline
Posts: 2
Improper syntax?
Oct 22nd , 2009, 6:18pm
Hey all, I'm taking a class on Processing, so I'm by no means great at it. I've taken programming classes before so I know the logic behind what I'm trying to do but the friggin' syntax is killing me. Anyway, with this function, it's got 2 parameters, one to pass an image into and the other for the desired size of a block of pixels (the whole point of this function is to take an image, and when the left mouse button is pressed, it causes the image to pixellate until it is no longer clear, and the right mouse button to go in the other direction until the image is very clear. ANYWAY, here's the code: PImage img; int howMuch = 5; void setup() { size(1000, 1000); img = loadImage("zombie.jpg"); } void pixImage(img, 5) { PImage imgCopy = new PImage(img.width, img.height); imgCopy.copy(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height); for (int y = 0; y < imgCopy.height; y += howMuch) { for (int x = 0; x < imgCopy.width; x += howMuch) { float r = 0.0, g = 0.0, b = 0.0; int yChunk = min(howMuch, imgCopy.height - y); int xChunk = min(howMuch, imgCopy.width - x); int count = xChunk * yChunk; for (int j = 0; j < yChunk; ++j) { for (int i = 0; i < xChunk; ++i) { color c = imgCopy.get(x+i, y+j); r += red(c); g += green(c); b += blue(c); } } color c = color(r / count, g / count, b / count); for (int j = 0; j < yChunk; ++j) { for (int i = 0; i < xChunk; ++i) { imgCopy.set(x+i, y+j, c); } } } } image(imgCopy, 0, 0); } I'm pretty confused obviously, any help would be hot. Thanks