Advertisement
JoshuaDavis

buildCube as replacement for box()

Mar 9th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. /*
  2.  
  3. // find out what cam you have by making this code in a sketch
  4.  
  5. import processing.video.*;
  6. Capture cam;
  7.  
  8. void setup() {
  9.     size(1280,720);
  10.     println( Capture.list() );
  11. }
  12.  
  13. */
  14.  
  15. import processing.video.*;
  16. Capture cam;
  17.  
  18. int    stageW      = 1280;
  19. int    stageH      = 720;
  20.  
  21. int    camW        = 1280;
  22. int    camH        = 720;
  23. float  cubeSpacing = 10.0;
  24. float  cubeSize    = 9.0;
  25.  
  26. PImage _t;
  27.  
  28. void settings() {
  29.     size(stageW, stageH, P3D);
  30. }
  31.  
  32. void setup() {
  33.     _t = loadImage("imageName.png");
  34.  
  35.     cam = new Capture(this, camW, camH, "HD Pro Webcam C920", 30);
  36.     cam.start();
  37. }
  38.  
  39. void draw() {
  40.     background(0);
  41.  
  42.     translate(stageW/2, stageH/2);
  43.  
  44.     rotateY(frameCount*0.01);
  45.  
  46.     for (int x = 0; x < camW; x += cubeSpacing) {
  47.         for (int y = 0; y < camH; y += cubeSpacing) {
  48.             color pixelColor = cam.get(x, y);
  49.             float b = map(brightness(pixelColor), 0, 255, 0, 15);
  50.             pushMatrix();
  51.                 translate(x - camW/2, y - camH/2);
  52.  
  53.                 strokeWeight(0);
  54.                 noStroke();
  55.                 noFill();
  56.  
  57.                 tint(pixelColor);
  58.  
  59.                 buildCube(cubeSize/2, cubeSize/2, (b*cubeSpacing)/2 );
  60.             popMatrix();
  61.         }
  62.     }
  63.     noTint();
  64. }
  65.  
  66. void buildCube(float _w, float _h, float _d) {
  67.     beginShape(QUADS);
  68.         textureMode(NORMAL);
  69.         texture(_t);
  70.  
  71.         // FRONT
  72.         vertex( -(_w), -(_h),  (_d),   0, 0);
  73.         vertex(  (_w), -(_h),  (_d),   1, 0);
  74.         vertex(  (_w),  (_h),  (_d),   1, 1);
  75.         vertex( -(_w),  (_h),  (_d),   0, 1);
  76.  
  77.         // BACK
  78.         vertex(  (_w), -(_h), -(_d),   0, 0);
  79.         vertex( -(_w), -(_h), -(_d),   1, 0);
  80.         vertex( -(_w),  (_h), -(_d),   1, 1);
  81.         vertex(  (_w),  (_h), -(_d),   0, 1);
  82.  
  83.         // TOP
  84.         vertex( -(_w), -(_h), -(_d),   0, 0);
  85.         vertex(  (_w), -(_h), -(_d),   1, 0);
  86.         vertex(  (_w), -(_h),  (_d),   1, 1);
  87.         vertex( -(_w), -(_h),  (_d),   0, 1);
  88.  
  89.         // BOTTOM
  90.         vertex( -(_w),  (_h),  (_d),   0, 0);
  91.         vertex(  (_w),  (_h),  (_d),   1, 0);
  92.         vertex(  (_w),  (_h), -(_d),   1, 1);
  93.         vertex( -(_w),  (_h), -(_d),   0, 1);
  94.  
  95.         // LEFT
  96.         vertex( -(_w), -(_h), -(_d),   0, 0);
  97.         vertex( -(_w), -(_h),  (_d),   1, 0);
  98.         vertex( -(_w),  (_h),  (_d),   1, 1);
  99.         vertex( -(_w),  (_h), -(_d),   0, 1);
  100.  
  101.         // RIGHT
  102.         vertex(  (_w), -(_h),  (_d),   0, 0);
  103.         vertex(  (_w), -(_h), -(_d),   1, 0);
  104.         vertex(  (_w),  (_h), -(_d),   1, 1);
  105.         vertex(  (_w),  (_h),  (_d),   0, 1);
  106.     endShape(CLOSE);
  107. }
  108.  
  109. void captureEvent(Capture c) {
  110.     c.read();
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement