Created
January 11, 2019 18:56
-
-
Save federico-pepe/a2b00b1e3292a75645a64c53950332a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(img.width, img.height); | |
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