Processing – Waves [syphon]

waves1 waves2 waves3waves4

//Tells Processing we're going to utilize the syphon library
import codeanticode.syphon.*;
//Declares the canvas we will draw to, necessary for Syphon
int brickWidth = 40;
int brickHeight = 2;
int cols = 20;
int rows = 24;
int columnOffset = 60;
int rowOffset = 30;
float rotationIncrement = 0.5;
PGraphics canvas;
//Declares the Syphon Server
SyphonServer server;
void setup() {
//typical size function, with added argument that is necessary for Syphon
size(1280,720, P3D);
//noLoop();
//Sets up the canvas, make it match the desired size of your sketch
canvas = createGraphics(1280, 720, P3D);
// Create syhpon server to send frames out.
server = new SyphonServer(this, "Processing Syphon");
}
void draw() {
 //Tell processing to begin drawing to the canvas instead of to the sketch
 canvas.beginDraw();

 //Typical drawing functions, but applied to canvas instead of the sketch itself
 brickWidth = millis()/250; 

 canvas.background(0);
canvas.smooth(50);
canvas.fill(255);
canvas.stroke(255);
 canvas.translate(30, 30);
 for (int i=0; i<cols; i++) {
 canvas.pushMatrix();
 canvas.translate(i * columnOffset, 0);
 float r = random(-QUARTER_PI, QUARTER_PI);
 int dir = 1;
 for (int j=0; j<rows; j++) {
 canvas.pushMatrix();
 canvas.translate(0, rowOffset * j);
 canvas.rotate(r/5);
 canvas.rect(-brickWidth/2, -brickHeight/2, brickWidth, brickHeight);
 canvas.popMatrix();
 r += dir * rotationIncrement;
 if (r > QUARTER_PI || r < -QUARTER_PI) dir *= -1;
 }
 canvas.popMatrix();

 }

 //Tell processing we're done drawing to canvas
 canvas.endDraw();

 //Draws contents of canvas to our sketch so we can see whats going on
 image(canvas, 0, 0);

 //Sends contents of canvas through Syphon Server to MadMapper! Yay!
 server.sendImage(canvas);
}

Tutorial: Using Syphon with Processing to stream video into MadMapper.

Advertisements

Tags: , , , , , , , , ,

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

%d bloggers like this: