März 5, 2012
PImage myImage; int dimension; int c; boolean cFlag; void setup() { background(0); size(200, 200); myImage = loadImage("ghost.png"); dimension = (myImage.width*myImage.height); } void draw() { // Two loops allow us to visit every column (x) and every row (y). myImage.loadPixels(); // Loop through every pixel column // Loop through every pixel column if (millis()%10 == 0) { for (int x = 0; x < myImage.width; x++ ) { // Loop through every pixel row for (int y = 0; y < myImage.height; y++ ) { // Use the formula to find the 1D location int loc = x + y * myImage.width; // The location in the pixel array is calculated via our formula: 1D pixel location = x + y * width if (x % 2 == 0 && y % 2 == 0) { // If we are an even column if (c>=255) cFlag = true; if (c<=0) cFlag = false; //print("*"); if (cFlag) c--; if (!cFlag) c++; //println(c); myImage.pixels[loc] = color(c+50, 10+c, 100+c); } } } } myImage.updatePixels(); image(myImage, 0, 0); }