Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

loadPixel – first example

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

&nbsp;
 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);
}