Claire Lee – Project 09 – Computational Portrait

project09

/* 
Claire Lee
15-104 Section B
Project-09
*/

var portraitImage;

function preload() {
    var portraitImageURL = "https://i.imgur.com/yxlQW1j.jpg"
    portraitImage = loadImage(portraitImageURL);

}

function setup() {
    createCanvas(600, 800);
    background(0);
    portraitImage.loadPixels();
    frameRate(100);
}

function draw() {
    var px1 = random(width);
    var py1 = random(height);
    var px2 = px1 + random(-20, 20);
    var py2 = py1 + random(-20, 20);
    var px3 = px1 + random(-20, 20);
    var py3 = py1 + random(-20, 20);
    var px4 = px1 + random(-20, 20);
    var py4 = py1 + random(-20, 20);
    var ix = constrain(floor(px1), 0, width - 1);
    var iy = constrain(floor(py1), 0, height - 1);
    var colorAtXY = portraitImage.get(ix, iy);

    noStroke();
    fill(colorAtXY);
    quad(px1, py1, px2, py2, px3, py3, px4, py4);

}

This portrait project was really interesting because we got to work with inserting and manipulating images from external sources. It took me a while to understand what each piece of code was meant to do, but it turned out to be fairly straightforward. I tried experimenting with different degrees of randomness for the shapes. Orignally, I was trying to go for a clean-cut geometric look, but I ended up liking the look of multi-layered small shapes better because the smaller shapes kind of resemble rough brushstrokes.

The “finished” portrait
Original image. This is a self-portrait!

Chelsea Fan-Project-09-Computational Portrait

I chose a portrait of my friend Katrina. I spent a long time deciding how to create the portrait and I eventually decided on drawing squares in a continuous and slightly randomized line.

Portrait

/* Chelsea Fan
Section 1B
chelseaf@andrew.cmu.edu
Project-09
*/
//important variables
var hiddenImage; 
var xCoord = 200;
var yCoord = 200;
//Speed variables
var xOff = 5;
var yOff = 5;

function preload() {
    //preload image
    var myImage = "https://i.imgur.com/mBLofJe.png"
    hiddenImage = loadImage(myImage);
}

function setup() {
    createCanvas(319, 360); //set canvas to image size
    pixelDensity(1);
    background(0); //black background
    hiddenImage.loadPixels(); //load image
    frameRate(50);
}

function draw() {
    //get image coloring
    var ix = constrain(floor(xCoord), 0, width);
    var iy = constrain(floor(yCoord), 0, height);
    var imageColor = hiddenImage.get(ix, iy);

    //Bounce off right side
    if (xCoord>=width || xCoord<=0){
        xOff = -xOff;
        yOff = random(-5, 5);
    }

    //Bounce off top and bottom
    if (yCoord>=height || yCoord<=0){
        yOff = -yOff;
        xOff = random(-5, 5);
    }

    //Rectangle move
    xCoord = xCoord + xOff;
    yCoord = yCoord + yOff;

    //Rectangle color
    noStroke(); //no outline of rectangles
    fill(imageColor); //fill based on hiddenImage coloring
    rect(xCoord, yCoord, 5, 5); //draw rectangles
}

Image after about 10 minutes
Image after about 1 minute.

Katrina Hu – Project 09 – Computational Portrait

sketch_project09

/*Katrina Hu
15104-C
kfh@andrew.cmu.edu
Project-09*/

var originalImage;

function preload() {
    var myImageURL = "https://i.imgur.com/g3iK76T.jpg";
    originalImage = loadImage(myImageURL);
}
function setup() {
    createCanvas(480, 480);
    background(0);
    originalImage.loadPixels();
    frameRate(500);
}

function draw() {
    //defining the variables
    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 = originalImage.get(ix, iy);

    //drawing the random dashes
    strokeWeight(4);
    stroke(theColorAtLocationXY);
    line(px + random(-10, 10), py + random(-10, 10), px + random(-10, 10), py + random(-10, 10));

    //drawing the random ellipses
    fill(theColorAtLocationXY);
    ellipse(px, py, random(1, 8), random(1, 8));
}

I chose to make a portrait of my friend Chelsea. It was fun to experiment with the random sizes and positions of my ellipses and lines.

The finished portrait(after about 5 minutes)
The original photograph

Steven Fei-Project 09-Portrait


sketch

This project is my approach to create an impressionist paintings while giving the drawing some “old-looking” effect by adding the dirt points according to the lightness of each pixel in the original image. Random lines are drawn with the same pixel color to imply a sense of brush or pencil stroking. The larger rectangles are the protagonists in the drawing to fulfill the portrait by occupying relatively large pixel areas.

Self Portrait Original Photo

Stage 0-a scattering layout of brush strokes

stage 1-the final progression by applying the brush strokes with the dirt points

 

//Steven Fei
//Project 09
//Section - A
//zfei@andrew.cmu.edu
var underlyingImage;

function preload() {
    // preload the photo
    var myImageURL = "https://i.imgur.com/GI56Ww2.jpg";
    underlyingImage = loadImage(myImageURL);
}

function setup() {
    // setting up the canvas according to the dimensions of the photo
    createCanvas(600, 450);
    background("pink");
    underlyingImage.loadPixels();
    frameRate(400);
}

function draw() {
    
    var px = random(width); // random points to have strokes
    var py = random(height); // random points to have strokes
    var count = int(px) % 2; // decide the conditionals when to apply the two drawing schedules
    var colorAt = underlyingImage.get(px, py); // retrieve the pixel of the photo
    var brightnessAt = brightness(colorAt); // retrieve the brightness of the point
    var light = lightness(colorAt); // retrieve the lightness of the point
    var cR = map(brightnessAt, 0, 255, 4, 12); // maping the corresponding radius and size of the circles and rectangles
    var angle = random(0, PI); // give a random stroke angle 
    noStroke();
    //conditionals to draw some grey scale dirt points when count is 0
    if(count == 0){
        push();
        fill(light, px % width * 0.07);
        translate(px,py);
        circle(0,0,cR * 0.8);
        pop();
    }
    //conditionals to draw the rectangular strokes to re-portray the original photo
    if(count == 1){
        push();
        fill(colorAt, px % width * 0.5);
        rectMode(RADIUS);
        translate(px, py);
        rotate(angle);
        rect(0,0,cR,cR);
        pop();
        //draw a random trace to represent the brush stroke
        stroke(colorAt, px % width * 0.2);
        strokeWeight(2);
        line(px + random(10), py + random(10), px + random(10), py + random(10));
    }
    
    
}

Emma NM-Project-09(Custom Pixels)


customPixels

/* 
Emma Nicklas-Morris
Section B
enicklas
Project-09
Custom Pixels
*/

var portraitImg;

function preload() {
    var myImageURL = "https://i.imgur.com/Zfspsky.jpg";
    portraitImg = loadImage(myImageURL);
}

function setup() {
    // canvas proportional to image size
    createCanvas(portraitImg.width / 6, portraitImg.height / 6);
    background(255);
    portraitImg.loadPixels();
    frameRate(150);

}

function draw() {
    // get pixel color at that random location in image
    var ix = floor(random(portraitImg.width));
    var iy = floor(random(portraitImg.height));
    var colorLoc = portraitImg.get(ix, iy);

    noStroke();
    fill(colorLoc);

    // scale it to canvas size
    x = map(ix, 0, portraitImg.width, 0, width);
    y = map(iy, 0, portraitImg.height, 0, height);
    
    // creates a spiral like look
    var d = dist(width / 2, height / 2, x, y);
    d = d % 10;

    // draws the hexagons
    polygon(x, y, d, 6);


}

// https://p5js.org/examples/form-regular-polygon.html 
function polygon(x, y, radius, npoints) {
  let angle = TWO_PI / npoints;
  beginShape();
  for (let a = 0; a < TWO_PI; a += angle) {
    let sx = x + cos(a) * radius;
    let sy = y + sin(a) * radius;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}

I really enjoyed this project. It was fun to see it come about. I wanted to make my generative pixel image to be a bit more interesting by adding a circular/spiral like look and use hexagons instead of circles or rectangles. 

Jamie Park – Project 09

sketch

// Jamie Park (jiminp)            Project 9
// Section E

var myPic;

function preload(){
    //preload image from imgur
    var meURL = "https://i.imgur.com/XmiI0Iq.jpg";
    myPic = loadImage(meURL);
}

function setup(){
    //createCanvas and fill in the background
    createCanvas(400, 300);
    background(0);
    //load the pixels of the image
    myPic.loadPixels();
    frameRate(60);
}

function draw(){

    //draw rectangles at random points
    var px = random(width);
    var py = random(height);

    //crate variables that would fit into acquiring the colors of the image
    var cx = constrain(floor(px), 0, width);
    var cy = constrain(floor(py), 0, height);
    var colorLocation = myPic.get(cx, cy);

    //generate rectangular color blocks
    noStroke();
    fill(colorLocation);
    var ran = random(20);
    rect(px, py, ran, ran, random(10));
}

I created a computational portrait of a picture of me. In addition to randomizing the size of the squares, I randomized the degrees of angle in the edges, layering soft and hard rectangles on top of each other.

I really enjoyed this coding process and it was nice to see the final product come together and create a picture of me.

Process (left) and final product (right)

The photo I used to code my project

Sammie Kim – Project 09 – Portrait

sketch

//Sammie Kim
//Section D
//sammiek@andrew.cmu.edu
//Project 09 - Computational Portrait

var img;
var smallPoint;
var largePoint;
var pointSize;

//preloading image from imgur
function preload() {
    img = loadImage('https://i.imgur.com/yXi77UB.jpg');
}

//setting the speed and size of loading image pixels
function setup() {
    createCanvas(300, 300);
    background(0);
    imageMode(CENTER);
    img.loadPixels();
    frameRate(100);
    noStroke();
    smallPoint = 1;
    largePoint = 10;
}

function draw() {
    var x = floor(random(img.width)); //random x location for ellipse
    var y = floor(random(img.height)); //random y location for ellipse
    var imageColor = img.get(x, y); //picking the x, y coordinates from the image
    fill(imageColor); //fill the ellipses with the color from image
    //let the points get smaller toward the bottom of canvas that has more details
    var pointSize = map(y, 0, height, largePoint, smallPoint);
    ellipse(x, y, pointSize, pointSize);
}

This project was entertaining as I was able to recreate my own portrait by using points. Observing how the points would gradually generate the full photo, I purposely made the bottom half points tiny to better reflect the detailed areas.

Lanna Lang – Project 09 – Portrait

sketch

//Lanna Lang
//Section D
//lannal@andrew.cmu.edu
//Project 09 - Computational Portrait

var px = [];
var py = [];

//load the underlying image
function preload() {
    var imgURL = "https://i.imgur.com/mSgPk6o.jpg";
    underlyingImage = loadImage(imgURL);
}

function setup() {
    createCanvas(480, 480);
    background(0);
    underlyingImage.loadPixels();
    frameRate(10);
}

function draw() {

    //for loop to draw the random lines that draw
    //when the new frame is displayed
    for (var i = 0; i < frameCount; i++) {

        //the x and y array is
        //drawn randomly
        px[i] = random(width);
        py[i] = random(height);
        
        //get the color of the underlying image
        //at the specific x, y location
        var ix = constrain(floor(px[i]), 0, width-1);
        var iy = constrain(floor(py[i]), 0, height-1);
        var theColorAtLocationXY = underlyingImage.get(ix, iy);

        //the person is drawn with smaller lines = more detail
        //this if statement is for the head
        if (px[i] >= 230 & px[i] <= 400 && 
            py[i] >= 70 && py[i] <= 300) {
            strokeWeight(1);
            //the line drawn is the same color as the 
            //underlying image at its location
            stroke(theColorAtLocationXY);
            //the lines drawn is at a random angle
            line(px[i] + random(5), py[i] + random(5), 
                px[i] + random(10), py[i] + random(10));

        //this if statement is for the chest
        } else if (px[i] >= 30 & px[i] <= width && 
            py[i] >= 270 && py[i] <= 450) {
            strokeWeight(1);
            stroke(theColorAtLocationXY);
            line(px[i] + random(5), py[i] + random(5), 
                px[i] + random(10), py[i] + random(10));

        //this if statement is for the left hand & the sun
        } else if (px[i] >= 50 && px[i] <= 200 && 
            py[i] >= 90 && py[i] <= 220) {
            strokeWeight(1);
            stroke(theColorAtLocationXY);
            line(px[i] + random(5), py[i] + random(5), 
                px[i] + random(10), py[i] + random(10));

        //this if statement is for the left arm
        } else if (px[i] >= 10 & px[i] <= 120 && 
            py[i] >= 220 && py[i] <= 350) {
            strokeWeight(1);
            stroke(theColorAtLocationXY);
            line(px[i] + random(5), py[i] + random(5), 
                px[i] + random(10), py[i] + random(10));

        //the background is drawn with thicker lines = less detail
        } else {
            strokeWeight(4);
            stroke(theColorAtLocationXY);
            line(px[i] + random(10), py[i] + random(10), 
                px[i] + random(50), py[i] + random(50));
        }
    }
    
}

Process
Finished product
Original Photo (of my friend)

I struggled creating this code because I was very adamant about using random lines as my custom pixel and I couldn’t find out how to exactly execute it, but after using frameCount, I finally got it. I had a lot of fun writing my code, and this is one of my favorite photos I’ve taken so I am very satisfied with my final result.

Siwei Xie – Project 09 – Computational Portrait

sketch

//Siwei Xie
//Section B
//sxie1@andrew.cmu.edu
//Project-09-Computational Portrait

var photo;

//load my portrait from imgur
function preload() {
    var myImageURL = "https://i.imgur.com/4dPRyTE.png";
    photo = loadImage(myImageURL);
}

function setup() {
    createCanvas(480, 480);
    background(0);
    photo.loadPixels();
    frameRate(999999); //speed of generating image
}

function draw() {
    var px = random(width); //random x location for new rect
    var py = random(height); //random y location for new rect
    var ix = constrain(floor(px), 0, width-1); //contrain rect within canvas width
    var iy = constrain(floor(py), 0, height-1);//contrain rect within canvas height
    var theColorAtLocationXY = photo.get(ix, iy);//match rect colors with original photo

    noStroke();
    fill(theColorAtLocationXY);//retrieve color
    rect(px, py, random(10, 20), random(10, 20));//fill canvas with random-sized rect

}

It was fun creating animated portrait using my own photo. The matching process between colors and sizes of random rectangles, and the original image was a fascinating process.