Skip to content

Instantly share code, notes, and snippets.

@federico-pepe
Created February 16, 2018 11:30
Show Gist options
  • Save federico-pepe/01b2778dfe12fe6dbe33cb2977a2446b to your computer and use it in GitHub Desktop.
Save federico-pepe/01b2778dfe12fe6dbe33cb2977a2446b to your computer and use it in GitHub Desktop.
PImage img;
int soglia = 90;
int prob = 5;
int counter = 0;
float[] distanze;
ArrayList<Point> punti;
int x1, y1, x2, y2;
void setup() {
background(255);
img = loadImage("IMG_3300.jpg");
size(539, 700);
img.loadPixels();
punti = new ArrayList<Point>();
noFill();
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++ ) {
int loc = x + y*img.width;
if (brightness(img.pixels[loc])<soglia) {
if (random(100)<prob) {
punti.add(new Point(x, y));
//ellipse(x,y,2,2);
}
}
}
}
distanze = new float[punti.size()];
int iniziale = int(random(punti.size()));
x1 = punti.get(iniziale).x;
y1 = punti.get(iniziale).y;
}
void draw() {
if (punti.size() >= 30) {
int salto = 50;
for (int i = 0; i < punti.size (); i++) {
distanze[i] = dist(x1, y1, punti.get(i).x, punti.get(i).y);
}
int prossimo = int(random(punti.size()));
while (distanze[prossimo] > salto) {
prossimo = int(random(punti.size()));
counter++;
if (counter == 500000) {
salto = 1000;
counter = 0;
}
}
float curva = distanze[prossimo];
x2 = punti.get(prossimo).x;
y2 = punti.get(prossimo).y;
line(x1, y1, x2, y2);
//stroke(random(0,255), random(0,255), random(0,255));
//bezier(x1, y1, x1+random(-curva, curva),y1+random(-curva, curva), x2, y2, x2, y2);
/*
strokeWeight(5/log(curva));
if(curva > 50) {
strokeWeight(0.5);
}
*/
x1 = x2;
y1 = y2;
punti.remove(prossimo);
}
if(punti.size() == 30) {
save("Ritratto.jpg");
}
}
class Point {
int x;
int y;
Point(int _x, int _y) {
x = _x;
y = _y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment