Advertisement
Guest User

connectHUDF

a guest
Sep 23rd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.17 KB | None | 0 0
  1.  
  2. import megamu.mesh.*;
  3. import org.processing.wiki.triangulate.*;
  4. import blobDetection.*;
  5.  
  6. BlobDetection theBlobDetection;
  7.  
  8. //ArrayList triangles = new ArrayList();
  9. //ArrayList points = new ArrayList();
  10. ArrayList<Dot> dots;
  11.  
  12. int N = 1000;
  13.  
  14. int num = 10, d=30, br=100;
  15. float alpha =255;//int num = 6000, d=20, br=24, alpha=20;
  16. int bg=255, s=150;
  17.  
  18. color lines =color(150);
  19. color linesC =color(240);
  20. color[] blue = { color(50,250,150), color(250,50,100),color(0,250,250),color(250,250,250)};
  21. PImage img;
  22. PVector[] blobsxy;// = new PVector[N];
  23. float[][] points;
  24. int x =0;
  25. int y = 0;
  26. int d1 =60, d2 =0;
  27.  
  28.  
  29.  
  30. void setup() {
  31.  
  32.  //img = loadImage("face.png");
  33.  img = loadImage("ngc7023.jpg");
  34.  //img = loadImage("HUDF-1.jpg");
  35.  //img = loadImage("albireo.jpg");
  36.  //img = loadImage("heden.jpg");
  37.  //img = loadImage("elph.jpg");
  38.  //img = loadImage("t-rex inv.png");
  39.  //img = loadImage("letgo.png");
  40.  //img = loadImage("saltlake.jpg");
  41.  //img = loadImage("mandel.jpg");
  42.  //img = loadImage("zaki.png");
  43.  //img = loadImage("oum.png");
  44.  //img = loadImage("melegi.png");
  45.  //img = loadImage("naguib.png");
  46.  
  47.   size(img.width, img.height);
  48.   img.loadPixels();
  49.  
  50.   background(40);
  51.  
  52.   dots = new ArrayList<Dot>();
  53.   //tint(255, 200);
  54.  image(img, 0, 0);
  55.   frameRate(10);
  56.  
  57.   theBlobDetection = new BlobDetection(img.width, img.height);
  58.   theBlobDetection.setPosDiscrimination(false);
  59.   theBlobDetection.setThreshold(0.6f);
  60.   theBlobDetection.computeBlobs(img.pixels);
  61.  
  62.   blobsxy = new PVector[theBlobDetection.getBlobNb()];
  63.  
  64.   points = new float[theBlobDetection.getBlobNb()][2];
  65.  
  66.   for(int n =0; n< theBlobDetection.getBlobNb(); n++){
  67.   blobsxy[n] = new PVector(random(width), random(height));  
  68.   }
  69.  
  70.   blobsxy = getBlobs();
  71.   Delaunay myDel = new Delaunay( points );
  72.  
  73.   float[][] myEdges = myDel.getEdges();
  74.  
  75. for(int i=0; i<myEdges.length; i++){
  76.   strokeWeight(1);
  77.   //stroke(int(random(50,100)),int(random(105,205)),int(random(50,100)) ,50);
  78.   stroke(blue[i%2 +2],70);
  79.   float startX = myEdges[i][0];
  80.   float startY = myEdges[i][1];
  81.   float endX = myEdges[i][2];
  82.   float endY = myEdges[i][3];
  83.   line( startX, startY, endX, endY );
  84.   }
  85.  
  86. }
  87.  
  88. void draw() {
  89.  
  90.   d2 = d1 + 1;
  91.  
  92.   alpha=3+ 20*cos(frameCount%500);
  93.   //background(bg, 200);
  94.  tint(255, alpha);
  95.   //image(img,0,0);
  96.   //blobsToDots(blobsxy);
  97.   //getDots();
  98.    d1 = d2;
  99.   noLoop();
  100.   save("c"+frameCount+".png");
  101. }
  102.  
  103. void keyPressed() {
  104.  
  105.   save(random(2332)+".jpg");
  106. }
  107.  
  108. PVector[] getBlobs()
  109. {
  110.   Blob b;
  111.   for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++)
  112.   {
  113.     b=theBlobDetection.getBlob(n);
  114.     if (b!=null)
  115.     {
  116.         noFill();
  117.         strokeWeight(1);
  118.         stroke(255, 0, 0);
  119.         //rect(b.xMin*width, b.yMin*height, b.w*width, b.h*height );
  120.        
  121.         blobsxy[n].x = width*(b.xMin + b.w/2);
  122.         blobsxy[n].y = height*(b.yMin + b.h/2);
  123.        
  124.         points[n][0] = width*(b.xMin + b.w/2);
  125.         points[n][1] = height*(b.yMin + b.h/2);
  126.      }
  127.   }
  128.   return blobsxy;
  129. }
  130.  
  131. void blobsToDots(PVector[] blobsxy){
  132.  
  133.     for (int i=0; i<blobsxy.length/2; i++) {
  134.       dots.add(new Dot(blobsxy[int(random(blobsxy.length))]));
  135.       //points.add(new PVector(x,y));
  136.     }
  137.  
  138.   for (Dot d : dots) {
  139.     d.lineBetween();
  140.   }
  141. }
  142.  
  143.  
  144. void getDots(){
  145.  
  146.     for (int i=0; i<num; i++) {
  147.     int x = int(random(width));
  148.     int y = int(random(height));
  149.  
  150.     if (brightness(img.pixels[x+y*width])>br ) {
  151.  
  152.    //if (red(img.pixels[x+y*width])>br && blue(img.pixels[x+y*width])<100) {
  153.       dots.add(new Dot(new PVector(x, y)));
  154.       //points.add(new PVector(x,y));
  155.     }
  156.   }
  157.   // get the triangulated mesh
  158.   //triangles = Triangulate.triangulate(points);
  159.  
  160.   for (Dot d : dots) {
  161.     d.lineBetween();
  162.   }
  163. }
  164.  
  165.  
  166. class Dot {
  167.  
  168.   PVector loc;
  169.  
  170.   Dot(PVector _loc) {
  171.     loc = _loc;
  172.   }
  173.  
  174.   void lineBetween() {  
  175.     for (int i=0; i<dots.size (); i++) {
  176.       Dot other = (Dot) dots.get(i);
  177.       float distance = loc.dist(other.loc);
  178.       //if (distance >0 && distance < d) {
  179.       if (distance >d1 && distance < d2) {
  180.         stroke(255, alpha);
  181.         line(loc.x, loc.y, other.loc.x, other.loc.y);
  182.       }
  183.     }
  184.   }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement