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);

void draw() {


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;


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() {

Here is the image:




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.