Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Step 1. Import the video library
- import processing.video.*;
- int x=0, y=0;
- int rez = 5;
- int r = 2, sz = 2;
- float angle, d;
- // Step 2. Declare a Capture object
- Capture cam;
- //Step 2b. Declare a PImage to hold the mirrored web cam image
- PImage img;
- void setup() {
- size(480, 360);
- background(0);
- // Step 3. Initialize Capture object via Constructor
- cam = new Capture(this, width, height);
- cam.start();
- // Step 3b. Initialize 'mirror' image
- img = createImage(width, height, RGB);
- }
- void captureEvent(Capture cam) {
- // Step 4. Read the image from the camera.
- cam.read();
- }
- // Step 5. Display stuff.
- void draw() {
- //background(0);
- //image(cam, 0, 0);
- flipImage();
- //image(img, 0, 0);
- //slitScan();
- //dots();
- //pixelated();
- //if (frameCount%10==0) tile();
- //paint();
- kaleidoscope();
- }
- void flipImage() {
- img.loadPixels();
- cam.loadPixels();
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- img.pixels[y*width+x] = cam.pixels[y*width+(width-1-x)];
- }
- }
- img.updatePixels();
- }
- void slitScan() {
- copy(img, x, 0, 1, height, x, 0, 1, height);
- x = x + 1;
- if (x>width) x = 0;
- copy(img, 0, 0, width, height, 0, 0, width/5, height/5);
- }
- void dots() {
- // draw 50 random dots each frame
- for (int i=0; i<50; i++) {
- int x = (int) random(width);
- int y = (int) random(height);
- color c = img.get(x, y);
- fill(c, 150);
- noStroke();
- float sz = random(2, 10);
- ellipse(x, y, sz, sz);
- }
- copy(img, 0, 0, width, height, 0, 0, width/5, height/5);
- }
- void pixelated() {
- background(0);
- // map the resolution to the mouse position
- rez = (int) map(mouseX, 0, width, 1, 30);
- //rez = 10;
- // loop through the whole image to create the small boxes
- for (int x = 0; x < width; x += rez) {
- for (int y = 0; y <width; y += rez) {
- int cx = x + rez/2;
- int cy = y + rez/2;
- color c = img.get(cx, cy);
- fill(c);
- noStroke();
- rect(x, y, rez, rez);
- //float br = brightness(c);
- //float sz = map(br, 0, 255, 0.5, 1)*rez;
- //ellipse(cx, cy, sz, sz);
- }
- }
- if (mousePressed) {
- copy(img, mouseX, mouseY, 150, 150, mouseX, mouseY, 150, 150);
- }
- }
- void tile() {
- // how many tiles in one direction?
- int units = 4;
- // width of the tile
- int w = width/units;
- // height of the tile
- int h = height/units;
- // copying the webcam image to the tile
- copy(img, 0, 0, width, height, x, y, w, h);
- // moving to the next tile
- x = x + w;
- // if at the right border then move to start of new row
- if (x>width) {
- x = 0;
- y = y+h;
- // if at the bottom right corner then move to upper left corner again
- if (y >= height) y = 0;
- }
- }
- void paint() {
- if (mousePressed) {
- PImage tmp = img.get(mouseX, mouseY, 50, 50);
- tint(255, 150);
- image(tmp, mouseX, mouseY);
- }
- // resized actual video
- copy(img, 0, 0, width, height, 0, 0, width/5, height/5);
- // dot representing mouse position on the resized video in the top left corner
- fill(255);
- stroke(0);
- float px = map(mouseX, 0, width, 0, width/rez);
- float py = map(mouseY, 0, height, 0, height/rez);
- ellipse(px, py, 5, 5);
- }
- void keyPressed() {
- save(random(99999)+".png");
- }
- void kaleidoscope() {
- PImage tmp = cam.get();
- tmp.resize(width/2, height/2);
- //tint(255,50);
- image(tmp, 0, 0);
- scale(-1, 1);
- image(tmp, -width, 0);
- scale(-1, 1);
- scale(-1, -1);
- image(tmp, -width, -height);
- scale(-1, -1);
- scale(1, -1);
- image(tmp, 0, -height);
- scale(1, -1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement