Advertisement
xeromino

video

Mar 12th, 2017
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import processing.video.*;
  2.  
  3. int x, y;
  4. float angle, d;
  5. PVector[] v = new PVector[25];
  6.  
  7. Movie movie;
  8.  
  9. void setup() {  
  10.   size(480, 360);  
  11.   //movie = new Movie(this, "bowie.mp4");
  12.   movie = new Movie(this, "pokerface.mp4");  
  13.   //movie = new Movie(this, "canned.mp4");
  14.   //size(640, 360);
  15.   //movie = new Movie(this, "automaton.mp4");
  16.   //movie = new Movie(this, "holdup.mp4");  
  17.   //size(854, 480);
  18.   //movie = new Movie(this, "bunny.mov");  
  19.   //size(1280, 720);
  20.   //movie = new Movie(this, "beyonce.mp4");
  21.   background(0);
  22.  
  23.  
  24.   movie.play();
  25.  
  26.   initWalkers();
  27. }
  28.  
  29. void movieEvent(Movie movie) {  
  30.   movie.read();
  31. }
  32.  
  33. void draw() {
  34.   if (frameCount>5) {
  35.     //distort();  // holdup
  36.     //paintLines(); // automaton
  37.     paintStripes(); // bowie
  38.     //squares();  // pokerface
  39.  
  40.     //slitScan(); // bunny
  41.     //centerColorDots();  // bowie
  42.     //walkers();  // bunnie.mov
  43.     //if (frameCount%5==0) carousel(); // canned
  44.   }
  45.   //saveFrame("image-####.png");
  46. }
  47.  
  48. void distort() {
  49.   // video = series of images so can be treated like images
  50.   background(0);
  51.   //tint(255,150);
  52.   image(movie, 0, 0, mouseX, mouseY);
  53. }
  54.  
  55. void paintLines() {
  56.   // get color from the center of the image
  57.   color c = movie.get(movie.width/2, movie.height/2);
  58.   stroke(c);
  59.   // draw line
  60.   line(x, 0, x, height);
  61.   //line(0,y,width,y);
  62.   //line(x, y, width-x, height-y);
  63.   // move line
  64.   x++;
  65.   //y++;
  66.   if (x>width) {
  67.     x = 0;
  68.   }
  69.   /*
  70.   if (y>height) {
  71.    y = 0;
  72.    }
  73.    */
  74.  
  75.   // display small movie in upper left corner
  76.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  77. }
  78.  
  79. void paintStripes() {
  80.   // max height of the stripe  
  81.   int h = height/3;
  82.   // get color from the center of the image
  83.   color c = movie.get(width/2, height/2);
  84.   stroke(c);
  85.   // map the brightness of the pixel to the height of the rectangle
  86.   float br = brightness(c);
  87.   float sz = map(br, 0, 255, 30, h);
  88.   // draw line
  89.   rectMode(CENTER);
  90.   rect(x, y, 1, sz);
  91.   // move x and y
  92.   x++;
  93.   if (x>width) {
  94.     x = 0;
  95.     y = y + h/2;
  96.     if (y>height) y = 0;
  97.   }
  98.   // display small movie in upper left corner
  99.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  100. }
  101.  
  102. void squares() {
  103.   // get the color from the center of the image
  104.   color c = movie.get(width/2, height/2);
  105.   fill(c);
  106.   //noStroke();
  107.   // size of the squares
  108.   int sz = 10;
  109.   rect(x, y, sz, sz);
  110.   // move to the start of the next square
  111.   x = x + sz;
  112.   // if the squares have reached the right border, jump to the next row
  113.   if (x > width) {
  114.     x = 0;
  115.     y += sz;
  116.     // if the squares have reached the bottom right corner, jump to the top left corner again
  117.     if (y > height) {
  118.       y = 0;
  119.     }
  120.   }
  121.   // display small movie in upper left corner
  122.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  123. }
  124.  
  125. void slitScan() {
  126.   // copy one horizontal line from the image and display it
  127.   copy(movie, 0, y, width, 1, 0, y, width, 1);
  128.   // move down one row
  129.   y = y + 1;
  130.   // if at the bottom then restart at the top
  131.   if (y>height) {
  132.     y = 0;
  133.   }
  134.   // display small movie in upper left corner
  135.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  136. }
  137.  
  138.  
  139.  
  140. void centerColorDots() {
  141.   color c = movie.get(width/2, height/2);
  142.   fill(c, 150);
  143.   noStroke();
  144.   //line(x, 0, x, height);
  145.   float br = brightness(c);
  146.   float y = map(br, 0, 255, height, 0);
  147.   //point(x,y);
  148.   rect(x, y, random(20, 50), 5, 5);
  149.   x++;
  150.   if (x>width) x = 0;
  151.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  152. }
  153.  
  154. void walkers() {
  155.   float r = 5;
  156.   float sz = 2;
  157.   for (int i=0; i<v.length; i++) {
  158.     v[i].x += random(-r, r);
  159.     v[i].y += random(-r, r);
  160.     color c = movie.get(int(v[i].x), int(v[i].y));
  161.     noStroke();
  162.     fill(c, 150);
  163.     ellipse(v[i].x, v[i].y, sz, sz);
  164.     if (v[i].x > width || v[i].x < 0) v[i].x = width/2;
  165.     if (v[i].y > height || v[i].y < 0) v[i].y = height/2;
  166.   }
  167.   // display small movie in upper left corner
  168.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  169. }
  170.  
  171. void walkers2() {
  172.   for (int i=0; i<1; i++) {
  173.     float x = random(width);
  174.     float y = random(height);
  175.     int sz = (int) random(20,200);
  176.     PImage tmp = movie.get(int(x),int(y), sz,sz);
  177.     tint(255, random(10,150));
  178.     image(tmp, int(x), int(y));
  179.   }
  180.   // display small movie in upper left corner
  181.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  182. }
  183.  
  184.  
  185. void initWalkers() {
  186.   for (int i=0; i<v.length; i++) {
  187.     v[i] = new PVector(width/2, height/2);
  188.   }
  189. }
  190.  
  191. void carousel() {
  192.   PImage tmp = movie.get();
  193.   tmp.resize(width/5, height/5);
  194.   tint(255, 150);
  195.   pushMatrix();
  196.   translate(width/2, height/2);
  197.   rotate(angle);
  198.   imageMode(CENTER);
  199.   image(tmp, d, 0);
  200.   popMatrix();
  201.   angle += radians(5);
  202.   d += 1;
  203.   if (d>width*.7) {
  204.     d = 0;
  205.     angle = 0;
  206.   }
  207.   copy(movie, 0, 0, width, height, 0, 0, width/6, height/6);
  208.   //filter(GRAY);
  209. }
  210.  
  211. void keyPressed() {
  212. saveFrame("image-###.png");
  213. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement