Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 8th, 2018 51 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. class PointilizeLayer extends Layer {  
  2.   String letterOrder =
  3.     " .`-_':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLu" +
  4.     "nT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q";
  5.   char[] letters;
  6.  
  7.   PFont font;
  8.   float fontSize = 1.5;
  9.  
  10.   int textColumns, textRows;
  11.  
  12.   float[] bright;
  13.   char[] chars;
  14.  
  15.   PImage depth;
  16.   PImage img;
  17.  
  18.   Capture myCapture;
  19.   //Movie myCapture;
  20.  
  21.   PointilizeLayer (PApplet parent) {
  22.     super(parent, JAVA2D);
  23.    
  24.     //myCapture = new Capture(parent, width, height, 30);
  25.   }
  26.  
  27.   void setup() {
  28.     font = loadFont("UniversLTStd-Light-48.vlw");
  29.    
  30.     textColumns = 30;
  31.     textRows = 20;
  32.  
  33.   }
  34.  
  35.   void setKinect(PImage img, PImage depth) {
  36.     this.img = img;
  37.     this.depth = depth;
  38.   }
  39.  
  40.   void setCapture(Capture c) {
  41.     this.myCapture = c;
  42.    
  43.      
  44.     // for the 256 levels of brightness, distribute the letters across
  45.     // the an array of 256 elements to use for the lookup
  46.     letters = new char[256];
  47.     for (int i = 0; i < 256; i++) {
  48.       int index = int(map(i, 0, 256, 0, letterOrder.length()));
  49.       letters[i] = letterOrder.charAt(index);
  50.     }
  51.  
  52.     int count = myCapture.width * myCapture.height;
  53.  
  54.     // current characters for each position in the video
  55.     chars = new char[count];
  56.  
  57.     // current brightness for each point
  58.     bright = new float[count];
  59.     for (int i = 0; i < count; i++) {
  60.       // set each brightness at the midpoint to start
  61.       bright[i] = 128;
  62.     }        
  63.   }  
  64.  
  65.   float rawDepthToMeters(int depthValue) {
  66.     if (depthValue < 2047) {
  67.       return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
  68.     }
  69.     return 0.0f;
  70.   }
  71.  
  72.   void draw() {
  73.     if (!doStroke) noStroke(); else stroke(1);//32);//random(255));
  74.     //background(0,0);
  75.  
  76.     //if (myCapture.available()) myCapture.read();
  77.     //a += 0.01;
  78.    
  79.     //float rel = 1/mouseX*sin(a*a);
  80.     float rel = norm(mouseX,0,width);//width);//,0,1);
  81.    
  82.     int sq_mouseX = mouseX*mouseX;
  83.     int sq_mouseY = mouseY*mouseY;
  84.    
  85.     int numBlobs = 0;
  86.    
  87.     //rotate(PI);
  88.    
  89.     //float zoom = 150-map(sq_mouseY,0,height*height,0,150);
  90.     float zoom = map(mouseY,0,height,1,150);
  91.  
  92.     //float pointillize = (doNoNegative?offsetAmount:0)+map(sin(a*a)*(rel*1000), 0, width, 2, 150) ;//* in.getGain();
  93.     float pointillize = (doNoNegative?offsetAmount:0)+map(sin(a*a)*(rel*1000), 0, width, 1, 150) ;//* in.getGain();
  94.     //float pointillize = (doNoNegative?1:0) + lerp((rel*10*a), 2, 64); //map(a, 0, 1, 2, 64) ;//* in.getGain();
  95.     float pointillize_b = (doNoNegative?offsetAmount:0)+map(sin(b*b)*sin(b*b), 0, width, 1, 255) ;//* in.getGain();    
  96.     //float pointillize_b = map(sin(offsetAmount*offsetAmount)*sin(b),-1,1,2,255);
  97.    
  98.     //background(0,0);
  99.     if (doDrawRealFrame) {
  100.       /*pushMatrix();
  101.       scale(2,1);
  102.       image(myCapture,0,0);//,0,0);//,width,height);
  103.       popMatrix();*/
  104.       myCapture.loadPixels();
  105.       loadPixels();
  106.       for (int p = 0; p < width; p++) {
  107.            // Begin loop for height
  108.            for (int j = 0; j < height; j++) {    
  109.              pixels[j*width+p] =   myCapture.pixels[(width - p - 1) + j*width]; // Reversing x to mirror the image
  110.            }
  111.       }
  112.       updatePixels();
  113.       doDrawRealFrame = false;
  114.     }
  115.    
  116.    
  117.     if (doDrawDebug) {
  118.       drawDebug("pointillize", pointillize);
  119.       drawDebug("pointillize_b", pointillize_b);
  120.     }
  121.    
  122.     float half_pointillize = pointillize/2;
  123.     float half_pointillize_b = pointillize_b/2;
  124.     float sq_pointillize = pointillize*pointillize;
  125.     float sq_pointillize_b = pointillize_b*pointillize_b;
  126.    
  127.     if (!renderLetters) {
  128.  
  129.       //float requiredX = width/(zoom*pointillize); //* map(mouseY,0,height, 8, width);
  130.       //float requiredY = height/(zoom*pointillize); //(pointillize*map(mouseX,0,width,0,10)); //* map(mouseY,0,height, 6, height);
  131.       //float requiredX = max(width/(pointillize*2),10);
  132.       //float requiredY = max(height/(pointillize*2),10);
  133.       float requiredX = max(width/(pointillize*2),10);
  134.       float requiredY = max(height/(pointillize*2),10);
  135.      
  136.       int[] pixelmap;
  137.       if (kinect) {
  138.         pixelmap = img.pixels;
  139.       } else {
  140.         pixelmap = myCapture.pixels; //loadPixels();
  141.       }
  142.        
  143.       //for (int px = 0 ; px < width ; px+= width*requiredX) {
  144.         //for (int py = 0 ; py < height ; py+= height*requiredY) {
  145.      
  146.       //int numBlobs = (int) map(sq_mouseY, 0, height*height, 5, constrain(5000-((sq_pointillize*sq_pointillize)),10,4000));
  147.       numBlobs = (int) map(zoom, 0, 150, 5, constrain((requiredX * requiredY),5,5000));// constrain(5000-((sq_pointillize*sq_pointillize)/2),10,4000));
  148.       //numBlobs = (int) constrain(requiredX*requiredY,5,(width*height)/2/*(((5000*zoom)/100))*/);
  149.       //numBlobs = (int) map(requiredX*requiredY,0,(width*height),5,5000); ///*(((5000*zoom)/100))*/);      
  150.        
  151.       int oldShape = shape;  
  152.       if (shape==3) {
  153.         shape = (int)random(0,3);
  154.       }        
  155.          
  156.       for (int i = 0 ; i < numBlobs /*map((1/(mouseY*mouseY),0,1,50,3000)*/ ; i++) {
  157.         //float pointillize = map(random(width), 0, width, 2, 50);
  158.         int x = int(random(width));
  159.         int y = int(random(height));
  160.         //color pix = ((Capture)myCapture).get(width-x, y);
  161.         //color pix = myCapture.pixels[(width*y-1)+(width-x)];
  162.         color pix = pixelmap[(width*y-1)+(width-x)];
  163.        
  164.         //colorMode(doColorFuck?HSB:RGB);
  165.        
  166.  
  167.         if (doColorCunt) {
  168.           int a = (pix >> 24) & 0xFF;  // Faster way of getting red(argb)          
  169.           int r = (pix >> 16) & 0xFF;  // Faster way of getting red(argb)
  170.           int g = (pix >> 8) & 0xFF;   // Faster way of getting green(argb)
  171.           int b = pix & 0xFF;          // Faster way of getting blue(argb)
  172.           pix = color(
  173.             /*map((int)(r*r),0,64,1,255),
  174.             map((int)(g*g),0,64,1,255),
  175.             map((int)(b*b),0,64,1,255),*/
  176.             /*(int)(r*r)/(16*(pointillize_b*(g-20))),
  177.             (int)(g*g)/(16*(pointillize_b*(b-20))),   // <-- a good one with or without hte -20's
  178.             (int)(b*b)/(16*(pointillize_b*(r-20))),*/
  179.             (int)(r*r)/(16*(pointillize_b/8)),
  180.             (int)(g*g)/(16*(pointillize_b/8)),   // brighter
  181.             (int)(b*b)/(16*(pointillize_b/8))//,
  182.            
  183.             //255
  184.          );
  185.         }
  186.        
  187.        
  188.         if (doColorFuck)
  189.           pix -= (-pix*2*pointillize_b); //orig
  190.          
  191.         if (doColorWank) {
  192.           pix -= (-pix*2*(sq_pointillize_b));
  193.           //pix = ((255*255)/(pix*pix));
  194.         }
  195.        
  196.         if (doColorShift) {
  197.           //pix = (pix*=pointillize)/64;
  198.           pix += pix+(width/pointillize_b);
  199.         }
  200.        
  201.  
  202.         if (doColorZap) {
  203.           int a = (pix >> 24) & 0xFF;  // Faster way of getting red(argb)          
  204.           int r = (pix >> 16) & 0xFF;  // Faster way of getting red(argb)
  205.           int g = (pix >> 8) & 0xFF;   // Faster way of getting green(argb)
  206.           int b = pix & 0xFF;          // Faster way of getting blue(argb)
  207.          
  208.           //pix = color((offsetAmount*64)+r/2, (offsetAmount*64)+g/2, (offsetAmount*64)+b/2);          
  209.           if (r<128) r += ((float)255*(offsetAmount+1.0)); else r -= ((float)255*(offsetAmount+1.0));
  210.           if (g<128) g += ((float)255*(offsetAmount+1.0)); else g -= ((float)255*(offsetAmount+1.0));
  211.           if (b<128) b += ((float)255*(offsetAmount+1.0)); else b -= ((float)255*(offsetAmount+1.0));
  212.           pix = color(r,g,b);
  213.         }        
  214.        
  215.         //color pix = new Color(red);
  216.  
  217.         if (!doTint) {
  218.           fill(pix);
  219.         } else {
  220.           if (!doHexMode) {
  221.             //fill(pix, map(width-mouseX,0,width,0,128));
  222.             fill (pix, 128);
  223.           //fill(pix, doTint?128:255);
  224.           //fill(pix, doTint?random(0,
  225.           } else {
  226.             fill(pix, map(i,0,width,0,128)); // <--- interesting glitches - explore!!
  227.           }
  228.         }
  229.        
  230.         if (kinect) {
  231.           //pointillize = map(depth.pixels[width-x-1 + (y*width)],500,1500,1,3);
  232.           //pointillize = depth.pixels[width-x-1 + (y*width)]/256;
  233.           //short d = (short) depth.pixels[width-x-1 + (y*width)];
  234.           //d = (int)blue(d) * (int)green(d);
  235.           float d = depth.pixels[width-x-1 + (y*width)];
  236.           print ("d is " + d + ", ");
  237.           //d = depthInMeters = 1.0 / (d * -0.0030711016 + 3.3309495161);
  238.           //if (d<2047 && d>0)
  239.             //pointillize = constrain(d,4,50);
  240.           //pointillize = 0.000001*depth.pixels[width-x-1 + (y*width)];
  241.           //if (d>0 && d<2048) {
  242.            // pointillize = 55-map(d,0,2048,5,50);
  243.           //}
  244.           pointillize = d;
  245.         }
  246.        
  247.         //line(0,0, 0,0, x, y);
  248.         //if (random(1)<0.5)
  249.         //if (doHexMode) {
  250.           //Hexagon h = new Hexagon((Object) this, 0, 0, (int)pointillize);
  251.           //h.drawHex();
  252.         //} else {
  253.  
  254.           if (shape==0) {
  255.             //ellipse(x-(pointillize/2), y-(pointillize/2), pointillize, pointillize);
  256.             ellipse(x, y, pointillize, pointillize);
  257.           } else if (shape==1) {
  258.             rect(x-(half_pointillize),y-(half_pointillize),pointillize,pointillize);
  259.           } else if (shape==2) {
  260.             //shape(x-pointillize, y-pointillize, x+pointillize, y+pointillize);
  261.             //float x2 = x+=x*tan(random(60));
  262.             //float y2 = y+=x*cos(random(60));
  263.             float a = random(60);
  264.             pushMatrix();
  265.             //translate(x-(pointillize/2), y-(pointillize/2));
  266.             translate(x,y);
  267.             rotate(radians(a));//x,y);            
  268.             rect(-half_pointillize, -half_pointillize, pointillize, pointillize);
  269.             popMatrix();
  270.           }
  271. //        }
  272.         //}
  273.         //rotate(cos(a));
  274.         //triangle(x-(15*pointillize), y-(15*pointillize), x+15*pointillize, y-15*pointillize, x+5*pointillize, y+5*pointillize);
  275.         //else
  276.         //rect(x, y, pointillize, pointillize); //uncomment this line to use squares
  277.       }    
  278.      
  279.       shape = oldShape;
  280.      
  281.     } else {
  282.       // renderLetters
  283.       //renderWithLetters();
  284.     }
  285.    
  286.     drawFPS(numBlobs);
  287.    
  288.   }
  289.    
  290. /*  void renderWithLetters() {
  291.       //background(0);
  292.    
  293.       //pushMatrix();
  294.    
  295.       float hgap = width / textColumns;//float(myCapture.width);
  296.       float vgap = height / textRows; //float(myCapture.height);
  297.    
  298.       scale(max(hgap, vgap) * fontSize);
  299.       textFont(font, fontSize);
  300.    
  301.       int index = 0;
  302.       myCapture.loadPixels();
  303.       for (float y = 1; y < myCapture.height; y+=vgap) {
  304.    
  305.         // Move down for next line
  306.         //translate(0,  1.0 / fontSize);
  307.         index += width;
  308.    
  309.         //pushMatrix();
  310.         for (float x = 0; x < myCapture.width; x+=hgap) {
  311.           int pixelColor = myCapture.pixels[index];
  312.           // Faster method of calculating r, g, b than red(), green(), blue()
  313.           int r = (pixelColor >> 16) & 0xff;
  314.           int g = (pixelColor >> 8) & 0xff;
  315.           int b = pixelColor & 0xff;
  316.    
  317.           // Another option would be to properly calculate brightness as luminance:
  318.           // luminance = 0.3*red + 0.59*green + 0.11*blue
  319.           // Or you could instead red + green + blue, and make the the values[] array
  320.           // 256*3 elements long instead of just 256.
  321.           int pixelBright = max(r, g, b);
  322.    
  323.           // The 0.1 value is used to damp the changes so that letters flicker less
  324.           float diff = pixelBright - bright[index];
  325.           bright[index] += diff * 0.1;
  326.    
  327.           fill(pixelColor);
  328.           int num = int(bright[index]);
  329.           text(letters[num], textColumns*x, textRows*y);
  330.          
  331.           // Move to the next pixel
  332.           index+=hgap;//=hgap;
  333.    
  334.           // Move over for next character
  335.           //translate(1.0 / fontSize, 0);
  336.         }
  337.         //popMatrix();
  338.       }
  339.       //popMatrix();
  340.   }*/
  341.  
  342.   int lineCount = 0;
  343.   void drawDebug(String label, Object value) {
  344.     lineCount++;
  345.     fill(128);
  346.     text(label +":" + value, width-150, lineCount*20);
  347.     fill(255);
  348.     text(label + ":" + value, width-149, (lineCount*20)+1);
  349.     fill(0);
  350.     text(label + ":" + value, width-148, (lineCount*20)+2);
  351.    
  352.   }
  353.  
  354.   void drawFPS(int numBlobs) {
  355. /*    textFont(font,36);
  356.     // white float frameRate
  357.     fill(128,255);
  358.     rect(width-100, 20, 100, 0);
  359.     fill(255);
  360.    
  361.     text(numBlobs, width-100, 20);*/
  362.    
  363.     if (!doDrawDebug) {
  364.       lineCount = 0;
  365.       return;
  366.     }  
  367.    
  368.     drawDebug("--","fps");
  369.     drawDebug("fps", (int)frameRate);    
  370.     drawDebug("--","fps");
  371.    
  372.     drawDebug("doColorCycle", doColorCycle);        
  373.     drawDebug("doHexMode", doHexMode);  
  374.    
  375.     drawDebug("numBlobs", numBlobs);
  376.  
  377.     drawDebug("wave a", a);    
  378.     drawDebug("wave b", b);
  379.  
  380.    
  381.     drawDebug("doNoNegative", doNoNegative);
  382.     drawDebug("cycleOffset", cycleOffset);
  383.     drawDebug("offsetAmount", offsetAmount);
  384.    
  385.     drawDebug("timeScale", timeScale);
  386.    
  387.     drawDebug("--","render fx");
  388.    
  389.     drawDebug("doStroke",doStroke);
  390.     drawDebug("doTint", doTint);
  391.     drawDebug("--","--");
  392.     drawDebug("doColorZap", doColorZap);
  393.     drawDebug("doColorCunt", doColorCunt);    
  394.     drawDebug("doColorShift", doColorShift);
  395.     drawDebug("doColorFuck", doColorFuck);
  396.     drawDebug("doColorWank", doColorWank);
  397.    
  398.     drawDebug("--","--");    
  399.    
  400.     drawDebug("doDrawRealFrame", doDrawRealFrame);
  401.  
  402.    
  403.     lineCount = 0;
  404.  
  405.     //text(frameRate,20,20);
  406.     // gray int frameRate display:
  407.     //fill(200);
  408.     //text(int(frameRate),20,60);
  409.    
  410.     if (record) {
  411.       text("recording", 20, height-20);
  412.     }
  413.   }  
  414.  
  415. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top