Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import megamu.mesh.*;
- import org.processing.wiki.triangulate.*;
- import blobDetection.*;
- BlobDetection theBlobDetection;
- //ArrayList triangles = new ArrayList();
- //ArrayList points = new ArrayList();
- ArrayList<Dot> dots;
- int N = 1000;
- int num = 10, d=30, br=100;
- float alpha =255;//int num = 6000, d=20, br=24, alpha=20;
- int bg=255, s=150;
- color lines =color(150);
- color linesC =color(240);
- color[] blue = { color(50,250,150), color(250,50,100),color(0,250,250),color(250,250,250)};
- PImage img;
- PVector[] blobsxy;// = new PVector[N];
- float[][] points;
- int x =0;
- int y = 0;
- int d1 =60, d2 =0;
- void setup() {
- //img = loadImage("face.png");
- img = loadImage("ngc7023.jpg");
- //img = loadImage("HUDF-1.jpg");
- //img = loadImage("albireo.jpg");
- //img = loadImage("heden.jpg");
- //img = loadImage("elph.jpg");
- //img = loadImage("t-rex inv.png");
- //img = loadImage("letgo.png");
- //img = loadImage("saltlake.jpg");
- //img = loadImage("mandel.jpg");
- //img = loadImage("zaki.png");
- //img = loadImage("oum.png");
- //img = loadImage("melegi.png");
- //img = loadImage("naguib.png");
- size(img.width, img.height);
- img.loadPixels();
- background(40);
- dots = new ArrayList<Dot>();
- //tint(255, 200);
- image(img, 0, 0);
- frameRate(10);
- theBlobDetection = new BlobDetection(img.width, img.height);
- theBlobDetection.setPosDiscrimination(false);
- theBlobDetection.setThreshold(0.6f);
- theBlobDetection.computeBlobs(img.pixels);
- blobsxy = new PVector[theBlobDetection.getBlobNb()];
- points = new float[theBlobDetection.getBlobNb()][2];
- for(int n =0; n< theBlobDetection.getBlobNb(); n++){
- blobsxy[n] = new PVector(random(width), random(height));
- }
- blobsxy = getBlobs();
- Delaunay myDel = new Delaunay( points );
- float[][] myEdges = myDel.getEdges();
- for(int i=0; i<myEdges.length; i++){
- strokeWeight(1);
- //stroke(int(random(50,100)),int(random(105,205)),int(random(50,100)) ,50);
- stroke(blue[i%2 +2],70);
- float startX = myEdges[i][0];
- float startY = myEdges[i][1];
- float endX = myEdges[i][2];
- float endY = myEdges[i][3];
- line( startX, startY, endX, endY );
- }
- }
- void draw() {
- d2 = d1 + 1;
- alpha=3+ 20*cos(frameCount%500);
- //background(bg, 200);
- tint(255, alpha);
- //image(img,0,0);
- //blobsToDots(blobsxy);
- //getDots();
- d1 = d2;
- noLoop();
- save("c"+frameCount+".png");
- }
- void keyPressed() {
- save(random(2332)+".jpg");
- }
- PVector[] getBlobs()
- {
- Blob b;
- for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++)
- {
- b=theBlobDetection.getBlob(n);
- if (b!=null)
- {
- noFill();
- strokeWeight(1);
- stroke(255, 0, 0);
- //rect(b.xMin*width, b.yMin*height, b.w*width, b.h*height );
- blobsxy[n].x = width*(b.xMin + b.w/2);
- blobsxy[n].y = height*(b.yMin + b.h/2);
- points[n][0] = width*(b.xMin + b.w/2);
- points[n][1] = height*(b.yMin + b.h/2);
- }
- }
- return blobsxy;
- }
- void blobsToDots(PVector[] blobsxy){
- for (int i=0; i<blobsxy.length/2; i++) {
- dots.add(new Dot(blobsxy[int(random(blobsxy.length))]));
- //points.add(new PVector(x,y));
- }
- for (Dot d : dots) {
- d.lineBetween();
- }
- }
- void getDots(){
- for (int i=0; i<num; i++) {
- int x = int(random(width));
- int y = int(random(height));
- if (brightness(img.pixels[x+y*width])>br ) {
- //if (red(img.pixels[x+y*width])>br && blue(img.pixels[x+y*width])<100) {
- dots.add(new Dot(new PVector(x, y)));
- //points.add(new PVector(x,y));
- }
- }
- // get the triangulated mesh
- //triangles = Triangulate.triangulate(points);
- for (Dot d : dots) {
- d.lineBetween();
- }
- }
- class Dot {
- PVector loc;
- Dot(PVector _loc) {
- loc = _loc;
- }
- void lineBetween() {
- for (int i=0; i<dots.size (); i++) {
- Dot other = (Dot) dots.get(i);
- float distance = loc.dist(other.loc);
- //if (distance >0 && distance < d) {
- if (distance >d1 && distance < d2) {
- stroke(255, alpha);
- line(loc.x, loc.y, other.loc.x, other.loc.y);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement