Triangular Portrait

Hi all,

I experimented with making a portrait by using triangles.

Here is the code:

PImage img;

void setup() {
size(300, 335);
img = loadImage(“portrait.jpg”);
img.filter(POSTERIZE, 10);
smooth();
}

void draw() {
background(255);

loadPixels();

for (int y = 0; y < img.height; y+=10 ) {
for (int x = 0; x < img.width+5; x+=5) {
int loc = x + y*img.width;

stroke(img.pixels[loc]);
fill(img.pixels[loc]);

if (x %10 == 0) triangle(x-5, y, x, y+10, x+5, y);
else triangle(x-5, y+10, x, y, x+5, y+10);
}
}
}

void mousePressed() {
save(int(random(10))+”.jpg”);
}

Here is the image:

 

 

4

I also add a save function. If I press the mouse when it is running,  a image will be saved in the folder. The file name is random number from 0-10.

After doing this, I tried to modify my code to see if I could make the code to show the process of paint with triangles. And I think the “save” function will be very nice for showing the whole image development. I haven’t worked it out, but if anyone knows any reference that is close to this idea, please let me know:)

 

Comments are closed.