Class Exercise: Pixels

Using code and some of the new/old functions we learned on Processing, I fiddled around with the values to change the pixels and their movement in a certain image.

PImage img;
int cellSize=2;
int columns, rows;
void setup() {
  size(512, 512, P3D);
  img = loadImage("Elizabeth Taylor.jpeg");
  img.resize(width,height);
  noStroke();
  columns=width/cellSize;
  rows=height/cellSize;
}

void draw() {
  background(255);
  img.loadPixels();
  for (int i=0; i<columns; i++) {
    for (int j=0; j<rows; j++) {
      int x= i*cellSize+cellSize/4;
      int y= j*cellSize+cellSize/2;
      int loc = x+(y*height);
      color pix=img.pixels[loc];
      float z=map(brightness(pix), 10, 255, 0, mouseX);
      float t=map(brightness(pix),255,0,255,mouseY);
      pushMatrix();
      translate(x,y,z);
      fill(pix);
      rectMode(CENTER);
      ellipse(10,0,cellSize,cellSize);
      popMatrix();
    }
  }
  img.updatePixels();
}

 

Leave a Reply