Project-09 Portrait

img_5712

This is the self-portrait image I used for this project. I had a lot of trouble with uploading the image, I tried to use Imgur but couldn’t get it to work properly, and so I tried to publish it on here instead. Below is the code and computed portrait, I modified it so that it would be created out of randomly placed triangles.

sketch

//Rebecca Enright
//Section A
//renright@andrew.cmu.edu
//Portrait assignment

var portrait;

function preload() {
    var myImage = "https://courses.ideate.cmu.edu/15-104/f2016/wp-content/uploads/2016/10/IMG_5712-225x300.jpg";
    portrait = loadImage(myImage);
}

function setup() {
    createCanvas(500, 500);
    background(0);
    portrait.loadPixels();
    frameRate(10);
}

function draw() {
    var px = random(width);
    var py = random(height);
    var ix = constrain(floor(px), 0, width-1);
    var iy = constrain(floor(py), 0, height-1);
    var theColorAtLocationXY = portrait.get(ix, iy);

    noStroke();
    fill(theColorAtLocationXY);
    triangle(px + 10, py + 10, px, py, px - 10, py - 10);

}

Leave a Reply