January 30, 2014

RGB Channel Shifting

Top Image Source

Bottom Image Source

January 30, 2014

Sorting Governor Chris Christie

on left: sorting by 32bit ARGB color values

on right: sorting RGB channel values separately

Source Image

January 30, 2014

January 30, 2014
More pixel shifting experiments…
Source Image:
Processing Code:
//PixelShifting by Phillip Stearns 2014
PImage sourceImg;
int iteration;

void setup(){
  iteration=0;
  sourceImg = loadImage("shift.jpg");
  size(sourceImg.width, sourceImg.height);
}

void draw(){
  int yoffset = int(random(height));
  int xoffset= int(random(width));
  int randomRows= int(random(height)) - yoffset;
  int randomColumns=int(random(width)) - xoffset;
  
  for(int i = 0 ; i < randomRows ; i++){
  shiftRow(sourceImg, i+yoffset, 15);
  }
  for(int j = 0 ; j < randomColumns ; j++){
  shiftColumn(sourceImg, j+xoffset, 15);
  }
  image(sourceImg, 0, 0);
  sourceImg.save("shifted_" +nf(iteration, 3)+ ".png");
  iteration++;
}

void shiftRow(PImage image, int row, int shift){
  int[] buffer = new int[image.width];
  if (row < 0 || row >= height){
    println("Row value is out of range.");
  } else{
    for(int i = 0 ; i < image.width ; i++){
      buffer[(i+shift) % (image.width)] = image.pixels[row*image.width+i];
    }
    for(int j = 0 ; j < image.width ; j++){  

      sourceImg.pixels[row*image.width+j] = buffer[j];
    }
  }
  sourceImg.updatePixels();
}

void shiftColumn(PImage image, int column, int shift){
  int[] buffer = new int[image.height];
  if(column < 0 || column >= width){
    println("Column value is out of range.");
  }else{ 
    for(int i = 0 ; i < image.height ; i++){
      buffer[(i+shift) % (image.height)] = image.pixels[i*image.width+column];
    }
    for(int j = 0 ; j < image.height ; j++){  
      sourceImg.pixels[j*image.width+column] = buffer[j];
    }
  }
  sourceImg.updatePixels();
}

More pixel shifting experiments…

Source Image:

Processing Code:

//PixelShifting by Phillip Stearns 2014
PImage sourceImg;
int iteration;

void setup(){
  iteration=0;
  sourceImg = loadImage("shift.jpg");
  size(sourceImg.width, sourceImg.height);
}

void draw(){
  int yoffset = int(random(height));
  int xoffset= int(random(width));
  int randomRows= int(random(height)) - yoffset;
  int randomColumns=int(random(width)) - xoffset;
  
  for(int i = 0 ; i < randomRows ; i++){
  shiftRow(sourceImg, i+yoffset, 15);
  }
  for(int j = 0 ; j < randomColumns ; j++){
  shiftColumn(sourceImg, j+xoffset, 15);
  }
  image(sourceImg, 0, 0);
  sourceImg.save("shifted_" +nf(iteration, 3)+ ".png");
  iteration++;
}

void shiftRow(PImage image, int row, int shift){
  int[] buffer = new int[image.width];
  if (row < 0 || row >= height){
    println("Row value is out of range.");
  } else{
    for(int i = 0 ; i < image.width ; i++){
      buffer[(i+shift) % (image.width)] = image.pixels[row*image.width+i];
    }
    for(int j = 0 ; j < image.width ; j++){  

      sourceImg.pixels[row*image.width+j] = buffer[j];
    }
  }
  sourceImg.updatePixels();
}

void shiftColumn(PImage image, int column, int shift){
  int[] buffer = new int[image.height];
  if(column < 0 || column >= width){
    println("Column value is out of range.");
  }else{ 
    for(int i = 0 ; i < image.height ; i++){
      buffer[(i+shift) % (image.height)] = image.pixels[i*image.width+column];
    }
    for(int j = 0 ; j < image.height ; j++){  
      sourceImg.pixels[j*image.width+column] = buffer[j];
    }
  }
  sourceImg.updatePixels();
}

January 29, 2014
Playing with wrap around, pixel shift registers. Each row of pixels has been shifted a random amount.
Source Image

Playing with wrap around, pixel shift registers. Each row of pixels has been shifted a random amount.

Source Image

January 29, 2014
Image Source

Image Source

January 29, 2014

Toying around with averaging and sorting on RGB channels…

Source Image

January 27, 2014
Shift Registers and Ripple Counters

Shift Registers and Ripple Counters

January 26, 2014

//counter.pde by Phillip Stearns
//an exercise in creating composite objects in Processing
//logic circuit simulation

Counter counter;

void setup() {
  background(0);
  size(5, 5);
  counter = new Counter(height);
}

void draw() {
  saveFrame("counter_###.png");
  counter.clock();
  for (int x = 0 ; x < width ; x++) {    
    for (int y = 0 ; y < counter.length() ; y++) {
      counter.display(y, x, y);
    }
  }
  if (frameCount == pow(2,height)) {
    exit();
  }
}

/*********begin class definitions********/

//Counter is a class of objects that have n number of stages.
//The counter operates like a binary ripple counter similar to the CD4040.
//Creation arguments: int size
//Methods:
//clock() - increments the counter
//clock(boolean clockInput) - allows an external clock to increment the counter. triggered on "falling edge" transistion from true to false.
//reset() - sets all stages to false
//display() - prints the counter's internal state from Least significant bit to Most significant bit from left to right (reverse binary)
//display(int Q, int x, int y) - changes the pixel at the coordinates x, y to match the output state of stage Q
//length() returns int - number of stages in the current counter
//getState(int Q) - returns boolean - the value of stage Q


class Counter {
  FlipFlop[] register;

  Counter(int size) {
    register = new FlipFlop[size];
    for (int i = 0 ; i < register.length ; i++) {
      register[i] = new FlipFlop();
    }
  }

  void reset() {
    for (int i = 0 ; i < register.length ; i++) {
      register[i].reset();
    }
  }

  int length() {
    return register.length;
  }

  void clock() {
    for (int i = 0; i < register.length ; i++) {
      if (i == 0) {
        if (register[0].getState() == true) {
          register[0].setState(false);
        } 
        else if (register[0].getState() == false) {
          register[0].setState(true);
        }
      } 
      else if (i > 0) {
        register[i].flip(register[i-1].getState());
      }
    }
  }

  void clock(boolean clockInput) {
    for (int i = 0; i < register.length ; i++) {
      if (i == 0) {
        register[0].flip(clockInput);
      } 
      else if (i > 0) {
        register[i].flip(register[i-1].getState());
      }
    }
  }

  boolean getState(int Q) {
    return register[Q].getState();
  }

  void display() {
    for (int i = 0 ; i < register.length ; i++) {
      print(int(register[i].getState()));
    }
    println();
  }

  void display(int Q, int x, int y) {
    loadPixels();
    pixels[y*width + x]=color(int(register[Q].getState())*255);
    updatePixels();
  }

  //FlipFlop is a clas of objects that behave like flipflop logic circuits.
  //Creation arguments: boolean init - sets initial state (optional)
  //Methods:
  //flip(boolean clock) - causes the flipflop to change states. triggered by "falling edge", true to false, logic transistion.
  //setState(boolean set) - sets register to set
  //reset() - resets register state to false
  //getState() - returns boolean - the value of the state
  
  class FlipFlop {  
    boolean state;
    boolean currentClock;
    boolean previousClock;

    FlipFlop() {
      state=false;
    }

    FlipFlop(boolean init) {
      state=init;
    }

    void flip(boolean clock) {
      currentClock = clock;
      if (currentClock == false && previousClock == true) {
        if (state == true) {
          state = false;
        } 
        else if (state == false) {
          state = true;
        }
      }
      previousClock = currentClock;
    }

    void setState(boolean set) {
      state = set;
    }

    void reset() {
      state = false;
      currentClock = false;
      previousClock = false;
    }

    boolean getState() {
      return state;
    }
  }
}

January 21, 2014
Massive Linear Feedback Shift Register Party
made with Processing

Massive Linear Feedback Shift Register Party

made with Processing

January 16, 2014

3:26pm  |   URL: http://tmblr.co/ZX7FGw14VDrDc
  
Filed under: GIF art processing lfsr 
January 16, 2014
int redBuffer;
int blueBuffer;
int greenBuffer;
PImage display;
color pixel;
int iterationCount;

void setup(){
  iterationCount=0;
  redBuffer = int(random(pow(2,32)));
  greenBuffer =  int(random(pow(2,32)));
  blueBuffer =  int(random(pow(2,32)));
  display = createImage(100,100,RGB);
  frameRate(15);
  size(display.width,display.height); 
}

void draw(){
  generatePixels();
  image(display,0,0);
  //display.save(&#8220;frameOutput_&#8221;+nf(iterationCount,4)+&#8221;.png&#8221;);
  if (iterationCount &lt; 0){
    exit();
  }
  iterationCount++;
}

void generatePixels(){
  for (int i=0; i&lt;display.pixels.length;i++){
  redBuffer=shift(redBuffer, 26, 2);
  greenBuffer=shift(greenBuffer, 27, 26);
  blueBuffer=shift(blueBuffer, 9, 31);
  pixel = color(int(byte(redBuffer)),int(byte(greenBuffer)),int(byte(blueBuffer)));
  display.pixels[i]=pixel;
  }
  display.updatePixels();
}

int shift(int input, int tapPos1, int tapPos2){
  int register = input &#171;&#160;1 ^ ((input&#160;&#187; tapPos1 &amp; 1) ^ (input&#160;&#187; tapPos2 &amp; 1));
  return register;
}

int redBuffer;

int blueBuffer;

int greenBuffer;

PImage display;

color pixel;

int iterationCount;

void setup(){

  iterationCount=0;

  redBuffer = int(random(pow(2,32)));

  greenBuffer =  int(random(pow(2,32)));

  blueBuffer =  int(random(pow(2,32)));

  display = createImage(100,100,RGB);

  frameRate(15);

  size(display.width,display.height); 

}

void draw(){

  generatePixels();

  image(display,0,0);

  //display.save(“frameOutput_”+nf(iterationCount,4)+”.png”);

  if (iterationCount < 0){

    exit();

  }

  iterationCount++;

}

void generatePixels(){

  for (int i=0; i<display.pixels.length;i++){

  redBuffer=shift(redBuffer, 26, 2);

  greenBuffer=shift(greenBuffer, 27, 26);

  blueBuffer=shift(blueBuffer, 9, 31);

  pixel = color(int(byte(redBuffer)),int(byte(greenBuffer)),int(byte(blueBuffer)));

  display.pixels[i]=pixel;

  }

  display.updatePixels();

}

int shift(int input, int tapPos1, int tapPos2){

  int register = input « 1 ^ ((input » tapPos1 & 1) ^ (input » tapPos2 & 1));

  return register;

}

December 22, 2013

/*
sortTest by Phillip Stearns
last updated 2013 12 22
sorts ALL the pixels of an image from darkest to lightest using a bubble sorting algorithm
00000000 00000000 00000000 = black in 24bit RGB space
why is full saturation red > full saturation blue ?
11111111 00000000 00000000 > 00000000 00000000 11111111
WARNING - this process will take a long time
BUT… you can watch it in action!
*/

PImage somePixels;
int elementA;
int elementB;

void setup (){
  elementA=0;
  elementB=0;
  somePixels = loadImage(“kittenface_sm.jpg”);
  size(somePixels.width,somePixels.height);
}

void draw (){
  sortPixels();
  somePixels.updatePixels();
  image(somePixels, 0 , 0);
}

void sortPixels () {
  for(int index = 0; index < somePixels.pixels.length-1 ; index++){
  elementA=somePixels.pixels[index];
  elementB=somePixels.pixels[index+1];
    if (elementA > elementB) {
      somePixels.pixels[index]=elementB;
      somePixels.pixels[index+1]=elementA;
    } 
  }
}

(Source: fi.wall-online.net)

December 22, 2013

Pixel Sorting Sunset

A simple bubble sorting algorithm written in Processing sorts 64 pixels according to their 24bit RGB value.

December 6, 2013

Scanning Veil Test 01 from Phillip Stearns on Vimeo.

Video Source: An image of a sunset was scanned top to bottom, one row of pixels at a time. Individual video frames were created from each row of pixels in the image by first mirroring, then stretching them to the full height of the frame. The frames were then animated in sequence at 15fps.

Audio Source: Each row of pixels was exported as a string of 8bit RGB values. A file containing the RGB pixel data was rendered as 24bit floating point audio (each pixel rendered as an audio sample). The final exported audio playback rate was matched to the video (playback sample rate was adjusted only).

(Source: phillipstearns)