März 5, 2012
The pixels of the duck are modified by moving the mouse around in the vertical as well as the horizontal axis.PImage img; int res =5; int res2 = res; int rectSize = 4; boolean flag = true; long timeStamp = 0; boolean onOff = false; int pause = 2; void setup() { rectMode(CENTER); size(640, 480, P3D); img = loadImage("ducks.jpg"); noStroke(); smooth(); } void draw() { background(0); loadPixels(); img.loadPixels(); res = 1+(int)map(mouseX, 0, width, 1, 80); res2 = (int)map(mouseY, 0, height, 1, 80); if (millis() - timeStamp > pause) { // We must also call loadPixels() on the PImage since we are going to read its pixels. img.loadPixels(); for (int x = 0; x < img.width; x+=res2) { for (int y = 0; y < img.height; y+=res2) { // Calculate the 1D pixel location int loc = x + y*img.width; // Get the R,G,B values from image float b = brightness(img.pixels[loc]); fill(b); //drawRect(x,y); if (flag) rectSize++; if (!flag) rectSize--; if (rectSize>=res) flag = false; if (rectSize<=0) flag = true; ellipse(x, y, rectSize, rectSize); img.pixels[loc] = color(b); } } //img.updatePixels(); // Display the destination //image(img,0,0); timeStamp = millis(); } } void drawRect(int x, int y) { if (millis() - timeStamp > pause) { rect(x, y, rectSize, rectSize); timeStamp = millis(); rectSize++; } if (rectSize>=res) rectSize = 1; }