akluk-Project-09-portrait

sketch

// Alvin Luk
// akluk@andrew.cmu.edu
// Section A
// Project 9

// variable to store the image
var img;
var cur_x;
var cur_y;
var rand_x;
var rand_y;
var rand_t;
var type_shape;
var pix;
var siz;

function preload(){
  img = loadImage("https://i.imgur.com/z1yTE1v.jpg");
  img.loadPixels();
}

function setup(){
  createCanvas (477,478);
  background(255);
  noStroke();
  //set ellispe mode to center
  ellipseMode(CENTER);
  frameRate(10000);
}

function draw(){
  //Select random point on canvas to draw
  rand_x = random(img.width);
  rand_y = random(img.height);
  cur_x = floor(rand_x);
  cur_y = floor(rand_y);
  //get the value at the position of the image
  pix = img.get(cur_x, cur_y);
  //generate a random size of the shape
  siz = random(3,6);
  //randomize which shape to draw 
  type_shape = random([0,1,2]);
  fill(pix);

  //depending on the random value of type shape: choose triangle circle or square
  if (type_shape == 0){
  	triangle(cur_x, cur_y-(2/3)*siz, cur_x-(1/2)*siz, cur_y+(1/3)*siz, cur_x+(1/2)*siz, cur_y+(1/3)*siz); 	
  }
  else if (type_shape == 1){
  	ellipse(cur_x, cur_y,siz,siz);
  }
  else {
  	rect(cur_x-siz/2,cur_y-siz/2,siz,siz);
  }

}

For this portrait, I asked if my sister if I could use one of her older photos. For the project, I just played around with what variables I could randomize to make it more interesting. I decided to incorporate the three elementary shapes, a square, a triangle, and a circle to reconstruct my image. I also varied the size of the shapes that were used to reconstruct the image. Below are just some screen shots of the program, at it’s initial, intermediate, and “final” reconstruction of the image.

What the canvas looks like initially

Intermediate Stage

Final result

agusman-Project09-Portrait

sketch

//Anna Gusman
//agusman@andrew.cmu.edu
//Section E
//
//Assignment 06 B
var underlyingImage;
var vals = [0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001]; //declare array of pie slice percentages
var nVals = vals.length; //length of array values

var start = 0; //first set the starting point of the first arc = to 0
var end = start + vals[0] * 360;
//Set the ending point of arc relative to its starting point
//the arc + the percentage value (decimal * 360)

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

function setup() {
    createCanvas(400, 400);
    background(0);
    angleMode(DEGREES);
    underlyingImage.loadPixels();
    frameRate(5000);
}

function draw() {
    for (var i = 0; i < nVals; i++) {
      start = end;
      end = start + vals[i] * 360; //draw a new arc from the "end" of the preceding
      //arc for every i
      noStroke();
      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 = underlyingImage.get(ix, iy);
      fill(theColorAtLocationXY);
      arc(px, py, 30, 100, start, end);
    }
}

I had a ton of fun with this project, even though the outcome was not as expected. I was inspired by a few pieces I’d seen by Sergio Albiac with sample pixel colors across the circumference of randomly distributed circles.

I decided to play with the rotational theme myself. Here are some examples of my process.

Photograph of my twin sister, taken by me:

Experimenting with texture parameters: Dreary Downpour

Slightly more defined

Furry Golan

More furry Golan

Most furry Golan

atraylor – Project 09 – Section B

sketch

//atraylor@andrew.cmu.edu
//project 09
//Section B

var face = "https://i.imgur.com/q6OIZVm.jpg";
var imScale = 10;
var offset = [];
var step = [];
function preload(){
    currentImage = loadImage(face);
}
function setup() {
    createCanvas(480, 480);
    background(220);
    currentImage.loadPixels();
    for(var i = 0; i < 2400; i++){
        offset.push(random(-2, 2));
        step.push(random(-100, 100));
    }
}
function draw() {
    pixelDensity(1);
    // currentImage.loadPixels();
    currentImage.loadPixels();
    // Render the current image to the canvas.
    image(currentImage, 0, 0);
    background(230);

    for (var y = 0; y < currentImage.height; y++){ // y location of pixels
        for (var x = 0; x < currentImage.width; x++) { // x location of pixels
            var index = (x + y * currentImage.width) * 4; // to analyze the rgba values in the pixels

            var p = []; // the pixel array
            p[0] = currentImage.pixels[index]; // r
            p[1]= currentImage.pixels[index+1]; // g
            p[2] = currentImage.pixels[index+2]; // b
            p[3] = currentImage.pixels[index+3]; // a

            var brightP = brightness(p);
            //draw "pixels"
            fill(brightP);
            strokeWeight(.09);
            rect(x* imScale + noise(offset[x]), y* imScale + noise(offset[y]), imScale, imScale);
            offset[x] += step[x];
            offset[y] += step[y];
        }
    }
}

 

Here is a digital portrait of me and my sister, or my sister and me? We’re two years apart but people, to our confusion, always think we’re twins. We did a face-swap one day and it was hilarious: we didn’t seem to change at all.

merlebac Project-09-Portrait

Pixel Portrait

// Matthew Erlebacher
// Section B
// merlebac@andrew.cmu.edu
// Project-09

var underlyingImage;

function preload() {
    var myImageURL = "https://i.imgur.com/lcdPSVo.jpg";
    underlyingImage = loadImage(myImageURL);
    // Loads the image and turns it into a variable
}

function setup() {
    createCanvas(500, 480);
    background(0);
    underlyingImage.loadPixels();
    frameRate(60);
    // I increased the frame rate to 60 so it would appear faster
}

function draw() {
    var px1 = random(width);
    var py1 = random(height);
    // Creates random location for small square
    var px2 = random(width);
    var py2 = random(height);
    // Creates random location for large square
    var ix1 = constrain(floor(px1), 0, width-1);
    var iy1 = constrain(floor(py1), 0, height-1);
    // Constrains px1 and py1
    var ix2 = constrain(floor(px2), 0, width-1);
    var iy2 = constrain(floor(py2), 0, height-1);
    // Constrains px1 and py1
    var theColorAtLocationXY = underlyingImage.get(ix1, iy1);
    var theColorAtLocationXY = underlyingImage.get(ix2, iy2);

    noStroke();
    fill(theColorAtLocationXY);
    // Fills the squares with portions of the image
    rect(px1, py1, 6, 6);
    rect(px2, py2, 9, 9);
    // Generates random rectangles

    var theColorAtTheMouse = underlyingImage.get(mouseX, mouseY);
    stroke(theColorAtTheMouse);
    line(pmouseX, pmouseY, mouseX, mouseY);
}

Working on this project was extremely difficult for me. For some reason the image wouldn’t generate a large amount of the time. Some of the edits that I made were increasing the frame rate, and changing the ellipses to rectangles. I did this because I thought the rectangles looked more visually appealing and covered the screen more quickly.

jknip-Project-09-portrait

sketch

/*Jessica Nip
Section A
jknip@andrew.cmu.edu
Project-09
*/


var img;

//--------------------------
function preload() {
    //preload grandma's image
    img = loadImage("https://i.imgur.com/G6dnwgf.jpg");

}
 //-------------------------
function setup() {
    createCanvas(342,480);
    img.loadPixels();
    frameRate(200); //set fast frame rate
}
 
 //-------------------------
function draw() {
    //define X and Y pixels of image, randomize appearance position
    var Xpixel = constrain(floor(random(width)), 0, width-1);
    var Ypixel = constrain(floor(random(height)), 0, height-1);
    //image color = grab pixels from image
    var imgcolor = img.get(Xpixel, Ypixel);
    var randomSize = random(5,15);

    //set ellipse color to image pixel color
    fill(imgcolor);
    noStroke(); //remove border
    //set ellipse X and Y to randomized pixel positions
    ellipse(Xpixel, Ypixel, randomSize, randomSize); 
}



For this project, I wanted to create a fun randomized ellipse-based filter generated based on a photo of my grandmother. Below you will find some screenshots at different points of the rendering process. As the colors in the original image were fairly limited and grouped in simple forms, I wanted to use randomized ellipses to suggest those specific colors across the canvas from the beginning — the overall image also becomes more apparent early on due to the high visibility of these core forms.

enwandu-Project-09-Portrait

sketch

// Emmmanuel Nwandu
// enwandu@andrew.cmu.edu
// Section D
// Project-09: Computational Portrait

var underlyingImage;
var angle = 5;
var radius = 1;
var eWidth = 2;

function preload() {
    underlyingImage = loadImage("https://i.imgur.com/fP2WiY5.jpg?1");
}

function setup() {
    createCanvas(400, 360);
    background(0);
    underlyingImage.loadPixels();
    frameRate(5000);
}

function DrawSpiral(){
    // Start spiral in the middle of canvas
    translate(width/2, height/2);
    var x = cos(radians(angle))* radius;
    var y = sin(radians(angle))* radius;
    var centerX = 0;
    var centerY = 0;

    // Gets the color of the pixels in the underlaying image
    var theColorAtLocationXY = underlyingImage.get(width/2 - x, height/2 - y);

    fill(theColorAtLocationXY); // Colors the pixel based on the underlaying image
    noStroke(0);
    ellipse(centerX - x, centerY - y, eWidth, eWidth)

    //pixel dimensions
    angle += 2; //the angle between rays of pixels
    radius += 0.02; //the density of the spiral
    eWidth = eWidth + .0005; //the increase in pixel size
}

function draw(){
    DrawSpiral();
}

This computational portrait in one of myself. It is an image from my 60’s album cover entitled “A Romantic Evening With You”. I used a spiral of ellipses to generated the underlying image in order to give the portrait a nostalgic vinyl record type feel or spinning record.

Original:

Final Computational Portrait:

rmanagad-project09-sectione

sketch

//Robert Managad
//Section-E
//rmanagad@andrew.cmu.edu
//

var underlyingImage;

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

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

function draw() {
	var randomSize = random(5, 10);
	var randomDetailSize = random(1, 3);
	var pxDetailX = constrain(200, 280);
	var pxDetailY = constrain(40, 100)
    var px = random(width);
    var py = random(height);
    var dx = 5;
    var ix = constrain(floor(px), 0, width-1);
    var iy = constrain(floor(py), 0, height-1);
    var ixM = constrain(floor(mouseX), 0, width-1);
    var iyM =  constrain(floor(mouseY), 0, width-1);
    // creating variations in opacity
    var theColorAtLocationXY =  [red(underlyingImage.get(ix, iy)) + 5,
                                green(underlyingImage.get(ix, iy)) + 10,
                                blue(underlyingImage.get(ix, iy)),
                                + 90]
    var theColorAtLocationXYM =  [red(underlyingImage.get(ixM, iyM)) + 20,
                                green(underlyingImage.get(ixM, iyM)) + 10,
                                blue(underlyingImage.get(ixM, iyM)),
                                + 50]
    rectMode(CENTER);

    //creates stroke, no-fill rectangles for interactivity
    if (mouseIsPressed) {
   	strokeWeight(random(2, 6));
    stroke(theColorAtLocationXYM);
    rect(mouseX, mouseY, randomSize * 2, randomSize * 3);
	}
	noStroke();
	fill(theColorAtLocationXY);
	//larger pixels outside the face area
	if (px < 200 || px > 280 || py < 40 || py > 140) {
	ellipse(px, py, randomSize*3, randomSize*3.5);
	rect(px, py, randomSize*1.5, randomSize*1.5);
	}
	//smaller pixels within the face area
	else if (px > 200 || px < 280 || py > 40 || py < 140) {
	rect(px, py, randomSize*1.5, randomSize*1.5);
	}



}

    

I developed my pixel portrait program with a foggy window idea in mind, hence the changes in opacities and layering of randomly-generated pixels. To somewhat speed up the process of visualizing the background image, I incorporated an if statement involving mousePressed, where as long as the mouse is pressed strokes of rectangles will be drawn.

Below is a full canvas illustrating the background image, a self portrait.

rkondrup-Project-09-Computational-Portrait

sketch

// ryu kondrup
// rkondrup@andrew.cmu.edu
// sectionD
// project-09
var underlyingImage;
var ellipseSizeX;
var ellipseSizeY;


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

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


//MAKE THE DOTS LARGER FARTHER FROM THE CENTER
function draw() {

//to draw puzzle pieces spaced on a grid 12 pixels apart
    var px = floor(random(width/12))*12;
    var py = floor(random(height/12))*12;
    //to constrain puzzle pieces to canvas
    var ix = constrain(px, 0, width-1);
    var iy = constrain(py, 0, height-1);
    var theColorAtLocationXY = underlyingImage.get(ix, iy);

    noStroke();
    fill(theColorAtLocationXY);
    //to draw the actual pieces at random locations
    puzzle(px, py);

    var theColorAtTheMouse = underlyingImage.get(mouseX, mouseY);
    // stroke(theColorAtTheMouse);
    // line(pmouseX, pmouseY, mouseX, mouseY);
}
//to draw the puzzle piece
function puzzle(x, y) {
    push();
    translate(x, y);
    //blocks of puzzle piece
    rect(1, 4, 11, 3);
    rect(9, 7, 3, 8);
    rect(4, 7, 5, 5);
    rect(1, 12, 3, 3);
    //pegs of puzzle piece
    rect(5, 1, 3, 1);
    rect(6, 1, 1, 3);
    rect(12, 9, 3, 1);
    rect(14, 8, 1, 3);
    //final fills of puzzle piece
    rect(1, 7, 1, 1);
    rect(3, 7, 1, 1);
    rect(1, 11, 1, 1);
    rect(3, 11, 1, 1);
    rect(4, 12, 1, 1);
    rect(4, 14, 1, 1);
    rect(8, 12, 1, 1);
    rect(8, 14, 1, 1);
    pop();
}

My plan for this project was to create a puzzle that gradually completes itself. Using the marvelous Maggie as a subject wearing her signature origami hat, I made a single puzzle piece that could be repeated infinitely on a square grid. Although I initially had no idea how to draw a good-looking curved puzzle piece, i soon realized that the pieces were so small that I could draw them using only rectangles and end up with a recognizable piece at the end.
In the end I was relatively happy with the result, I only wish the final product could have a higher resolution, perhaps each piece could contain multiple colors.

hschung-Project-09

sketch

//Heidi Chung
//Section A
//hschung@andrew.cmu.edu
//Project-09

var baseImage;

function preload() {
    var myImageURL = "https://i.imgur.com/FLTyc1P.jpg?1"; // a picture of myself
    baseImage = loadImage(myImageURL); //loading the image
}

function setup() {
    createCanvas(480, 480);
    background(255);
    baseImage.loadPixels(); //loading the image's pixels
    frameRate(20);
    noStroke();
}

function draw() {
    image(baseImage, 0, height, baseImage.width/2, baseImage/height/2);
    var px = random(width); //random assembly of circles being drawn in regards to x
    var py = random(height);//random assembly of circles being drawn in regards to y
    var ix = constrain(floor(px), 0, width-1);
    var iy = constrain(floor(py), 0, height-1);
    var theColorAtLocationXY = baseImage.get(ix, iy); //extracting the colors of the image

    noStroke();
    fill(theColorAtLocationXY); //colors of circles match the image's colors at the appropriate positions
    var circleWidth = random(5, 30); //variable set so the circles have the same random width and height
    ellipse(px, py, circleWidth, circleWidth); //instead of making ellipses

    var theColorAtTheMouse = baseImage.get(mouseX, mouseY);
    fill(theColorAtTheMouse); //drawing with the mouse using the image's colors at the pixels

    var whatsUpTextX = pmouseX-25; //the position of the text relative to the mouse
    var whatsUpTextY = pmouseY-20;
    textSize(15); //the text says "what's up" in japanese
    text("どうしたの?", whatsUpTextX, whatsUpTextY); //what's up is dragged along by the mouse
}

function mousePressed() {
  var theColorAtTheMouse = baseImage.get(mouseX, mouseY); //extracting the colors of the image again
  strokeWeight(3); //white stroke around the text to see it better
  stroke(255); //the text says "are you okay?" in korean
  textSize(30); //when you click, a big "are you okay?" is drawn
  text("괜찮아?", pmouseX - 45, pmouseY);
}

I really enjoy post-impressionism, especially Van Gogh’s art. I love that he painted scenery and people with purposeful strokes and artistic, imprecise interpretation, especially in a time where people did not appreciate his art because it wasn’t “accurate” or exact to real life images. I love the smudges and smears he made in his works. So I thought it’d be fun to make a self-portrait that feels impressionistic. When you drag the mouse across the canvas, it “paints” words that say “what’s wrong” or “what’s up” in Japanese. When you click the mouse, it “paints” a word that says “are you okay” in Korean. I can read/speak both Japanese and Korean, and I thought it’d be interesting to have both languages in my project- to say that even if you can’t understand something, you can still visually appreciate it, like you can with Van Gogh’s works.

After many circles have been drawn
You can drag the mouse to “draw” on the canvas with the words that ask “what’s up?” in Japanese
When you click, the word that appears says “are you okay?” in Korean

dnoh-sectionD-project8-portrait

(edited to change sketch size)

click to change direction pixels come from.

sketch

//Daniel Noh
//Section D
//dnoh@andrew.cmu.edu
//Project-09

//global variables
var squares = [];
var direction;
var side;


function preload(){
    var picurl = "https://i.imgur.com/ABZ50uF.jpg";
    pic = loadImage(picurl);
}

function setup(){
    createCanvas(400,400);
    pic.loadPixels();
    background(0);
    direction = 30; //setting up initial values of the variables to start
    side = 0;
}



function drawsquares() {
    var ix = constrain(floor(this.x), 0, width-1);
    var iy = constrain(floor(this.y), 0, height-1);
    var colourXY = pic.get(this.x, this.y);//gets fill colour from image

    fill(colourXY);//fills with pixel colour
    noStroke();
    rect(this.x, this.y, this.size, this.size);
}


function movesquares() {//function to make the squares roll
    this.x += this.dx*0.1;
}

function portrait(px, py, pdx) {
    s = {x: px,
         y: py,
         dx: pdx,
         squares: drawsquares,
         speed: movesquares,
         size : random(1,3)//randomizes the size of each individual square
        }
    return s;
}
function draw(){
    noStroke();
    newlines = []; //empty array to hold lines
    for (var i=0; i<squares.length; i++){
        var s = squares[i];
        s.speed();//returns function speed
        s.squares();//returns function squares
        newlines.push(s);
    }
    squares = newlines;
}

function mousePressed(){//changes the side and the direction of the lines each time mouse is pressed
    direction = -1*direction;
    if (side == 0){
        side = 400;
    }
    else if (side == 400){
        side = 0;
    }

}
function mouseMoved() {
    var newsquare = portrait(side, mouseY, random(direction));
    squares.push(newsquare);
}

The initial idea for this sketch was to create a portrait that slowly appeared from the sides. However, to integrate the mouse, I made the pixels appear where mouseY is and made clicking change whether the pixels appeared from the right or left.

This is not the complete portrait, however this shows the code’s aesthetics better.