Wednesday, December 23, 2015

import megamu.mesh.*;

import java.util.Collections;

PImage img;
int[] vlerat = new int[800*800];
ArrayList <Integer> vleratShuffle = new ArrayList<Integer>();
float[] prop = new float[800*800];
color[] ngjyrat = new color[800*800];
int nrPikat = 1800;
int[] indekset = new int[nrPikat];
float dmax = 6;
void setup() {
  size(800,800);
  img = loadImage("a2.jpg");
  noLoop();
  for (int i = 0; i < width*height; i ++){
  vleratShuffle.add(i);;
  }
  Collections.shuffle(vleratShuffle);
}

void draw() {
  image(img, 0, 0,width,height);
  loadPixels();
  ngjyrat = pixels;
  for(int i = 0; i < width*height; i ++){
  float r = red(pixels[i]);
  float g = green(pixels[i]);
  float b = blue(pixels[i]);
  int vl = (int)(r+g+b);
  vlerat[i] = (int)map( vl , 0, 256*3 , 0, 255);
  prop[i] = map(vlerat[i],0,255,0,1);
  }
  updatePixels();
  int j = 0;
  while (j < nrPikat){
    float mm;
    float ii;
    for (int i = 0; i < width*height; i++){
    float rand = random(1.0);
    float mbledhja = rand + prop[vleratShuffle.get(i)];
    if (mbledhja > 1.15){indekset[j] = vleratShuffle.get(i); j++;}
    if(j==nrPikat-1){break;}
    }

  break;
  }
   background(0);

  fill(255);
  float[][] pikat = new float[nrPikat][2];
  for (int i =0; i < nrPikat; i++){
  PVector pv = kthim(indekset[i]);
  float diam = map(vlerat[indekset[i]], 0,255, 0, dmax);
  pikat[i][0] = pv.x;
  pikat[i][1] = pv.y;

 
    noStroke();
    fill(ngjyrat[indekset[i]]);
  ellipse(pv.x,pv.y,diam,diam);
  }

  Delaunay edg = new Delaunay(pikat);
  float[][] edges = edg.getEdges();

for(int i=0; i<edges.length; i++)
{
  float startX = edges[i][0];
  float startY = edges[i][1];
  float endX = edges[i][2];
  float endY = edges[i][3];

  stroke(ngjyrat[kth(endX, endY)]);
  line( startX, startY, endX, endY );
}

}

PVector kthim (int k){
int x = k%width;
int y = k/height;
return new PVector(x,y);
}

int kth (float x, float y){
return int(x) + int(y)*width;
}

No comments:

Post a Comment