Introduction to Processing (21CLHK 2013)

Download and install Processing from here (www.processing.org/download/).

Pixelate patch

Screen Shot 2013-01-26 at 10.52.02 AM

// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 16-7: Video pixelation

import processing.video.*;

// Size of each cell in the grid, ratio of window size to video size

int videoScale = 20;

// Number of columns and rows in our system

int cols, rows;

// Variable to hold onto Capture object
Capture video;
void setup() {
 size(640,480);

 // Initialize columns and rows
 cols = width/videoScale;
 rows = height/videoScale;
 video = new Capture(this,cols,rows,30);
 video.start(); 
 rectMode(CENTER);
 ellipseMode(CENTER);
}
void draw() {
 // Read image from the camera
 if (video.available()) {
 video.read();
 }
 video.loadPixels();

 // Begin loop for columns
 for (int i = 0; i < cols; i++) {
 // Begin loop for rows
 for (int j = 0; j < rows; j++) {

 // Where are we, pixel-wise?
 int x = i*videoScale;
 int y = j*videoScale;
 // Looking up the appropriate color in the pixel array
 color c = video.pixels[i + j*video.width];
 fill(c);
 stroke(0);
 //rect(x,y,videoScale,videoScale);
 ellipse(x, y, videoScale,videoScale);
 /*
 if (x%(videoScale*2)==0){
   ellipse(x, y, videoScale,videoScale); 
   }else{
    rect(x,y,videoScale,videoScale); 
  }
 */
  }
 }
}
Advertisements

One thought on “Introduction to Processing (21CLHK 2013)

  1. Pingback: 21CLHK Creative Code Recap | Hamlet's Thinking Cloud

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s