Generative Portrait

sketchDownload

 //Yanina Shavialena
 //Section B

//My portrait
var image;
//Places I've been/Want to go to
var words = ['Belarus','USA','Bulgaria','Poland','Spain','France','South Korea'];
//The state of mouse pressed
let pressedState = false;

//This function loads the image
function preload() {
    var imagelink= "https://i.imgur.com/CQ38vbw.jpg";
    image = loadImage(imagelink);
}
 
//This function created canvas and makes sure the picture is in dimensions of the canvas
function setup() {
    createCanvas(480, 480);
    image.resize(480, 480); 
    background(0);
    image.loadPixels();
    frameRate(10000000);
}
 
function draw() {
    //random x and y positions and get the color from that x and y from my portrait
    var x = random(width);
    var y = random(height);
    var c = image.get(x, y);

    if( pressedState == false){
        //random start controlling point
        var x1 = x + random(-25,25);
        var y1 = y + random(-25,25);
        //random final point
        var x3 = x + random(-15,15);
        var y3 = y + random(-15,15);
        //random final controlling point
        var x4 = x3 + random(-25,25);
        var y4 = y3 + random(-25,25);

        stroke(color(c));
        curve(x1, y1, x, y, x3, y3, x4, y4);

        //hearts at the beginning and final point
        heart(x,y,5,c);
        heart(x3,y3,5,c);
    }

    //puts words at random points
    else{
        noStroke();
        fill(c);
        textSize(random(10));
        text(random(words),x,y)
    }
}

//when mouse is pressed, mouseState is updated and the background is reset
function mousePressed(){
    if(pressedState == false) {
        pressedState = true;
    }
    else {
        pressedState = false;
    }
    background(0);
}

//creates hearts to use for the ends of the lines
function heart(x, y, size, color) {
    fill(color);
    beginShape();
    vertex(x, y);
    bezierVertex(x - size / 2, y - size / 2, x - size, y + size / 3, x, y + size);
    bezierVertex(x + size, y + size / 3, x + size / 2, y - size / 2, x, y);
    endShape(CLOSE);
}

I really enjoyed this project because I could finally implement the idea of pixels and creativity. It was hard to come up with something at first but then I thought about what could describe me in my portrait so I decided to use an emoji of a heart because I think love is one of the strongest feelings on Earth and after the click of a mouse multiple countries would pop up randomly to make up an image: one of the countries is where I was born, one of the countries is where I live right now, then the remaining countries are where I visited or where I want to visit.

Project 09 – Portrait

sketch
//Brandon Yi
//btyi@andrew.cmu.edu
//Section A


//Initialization
var img;
var counter = 0;

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


function setup() {
  img.resize(img.width/5, img.height/5); //Resizing image
  createCanvas(img.width, img.height); //Canvas size based on image size
  imageMode(CENTER);
  rectMode(CENTER);
  textAlign(CENTER);
  noStroke();
  background(255);
  img.loadPixels(); 
}

//drawing shapes based on mouse position to imitate loaded image
function draw() {
  if (counter == 0) {
    settingNumber();
    var pointcolor = img.get(mouseX, mouseY); //point color based on mouse position and image
    fill(pointcolor);
    rect(mouseX, mouseY, 15, 15); //draw rectangle in mouse position
  }
  else if (counter == 1) {
    settingNumber();
    var pointcolor = img.get(mouseX, mouseY);
    fill(pointcolor);
    ellipse(mouseX, mouseY, 15, 15); //draw circle in mouse position
  }
  else if (counter == 2) {
    settingNumber();
    var pointcolor = img.get(mouseX, mouseY);
    fill(pointcolor);
    rect(mouseX, mouseY, 30, 30);
  }
  else if (counter == 3) {
    settingNumber();
    var pointcolor = img.get(mouseX, mouseY);
    fill(pointcolor);
    ellipse(mouseX, mouseY, 30, 30);
  }
  else {
    settingNumber();
    var pointcolor = img.get(mouseX, mouseY);
    fill(pointcolor);
    rect(mouseX, mouseY, 50, 50);
  }
  
}

//Changing setting number and resetting canvas
function mousePressed() {
  counter++;
  counter = counter % 5;
  print(counter);
  background(255);
}

//Setting number in label
function settingNumber() {
    textSize(30);
    fill(0);
    rect(350, 590, 150, 50)
    fill(255);
    text("Setting " + (counter+1), 350, 600);
}

Project 09: Computational Portrait

sketch

//Julianna Bolivar
//jbolivar@andrew.cmu.edu
//Section D
//Computational Portrait

var img;

function preload(){
  //load image
  img = loadImage("https://i.imgur.com/eaETdlz.png");
  frameRate(10);
}


function setup() {
    createCanvas(400, 400);
}


function draw() {
    image(img, 0, 0, 400, 400);
    for(var row = 0; row <= 200; row++) {
        for(var col = 0; col <= 200; col++){
            var x = col * 5;
            var y = row * 5;
            //pixels
            var pixelColor = img.get(x*5, y*5);
            noStroke();
            fill(pixelColor);
            //draw circle
            circle(x + 30, y + 50, 5); 
        }
    }
}

I didn’t expect my frame in frame pixels to create a distorted effect, but I really like how it looks. The spaces in between the circles allow you to see some of the original image underneath.

Project 09: Computational Portrait

portrait
var img;

function preload() {
    img = loadImage("https://i.imgur.com/TWN7sA6.jpeg");
}

function setup() {
    createCanvas(300, 300);
    frameRate(60);
    noStroke();
    img.resize(width, height);
    img.loadPixels();
}

function draw() {
    fill(0);
    text("keep mouse pressed for different effect", 50, 10);

    if(mouseIsPressed) { // while mouse is pressed, generate random squares 
        let pix_x = floor(random(img.width));
        let pix_y = floor(random(img.height));
        let pix = img.get(pix_x, pix_y);
        fill(pix);
        var square_x = random(width);
        var square_y = random(height);
        let mapX = map(mouseX, 0, width, 0, 20);
        square(square_x, square_y, mapX);
    } else { // otherwise, use circles 
        let x = floor(random(img.width));
        let y = floor(random(img.height));
        let pix = img.get(x, y);
        fill(pix);
        circle(x, y, random(15)); //diameter random 
    }
}

I used an image that I found on imgur by Mihaela Noroc, a Romanian photographer. I chose this particular image because it involved a lot of vibrant colors, which I thought would be fun to work with. Here are some screenshots of my portrait:

Project 9: Computational portrait

sketchDownload

// Yash Mittal
// Section D

function preload(){
    Pimg = loadImage ("https://i.imgur.com/PLF0Wbf.jpg"); // load image
}

function setup () {
    createCanvas (310, 480);  
    frameRate (100000000000000);
    background (0);
    Pimg.resize (310, 480);
}

function draw () {

    var a = random (width);
    var b = random (height);
    var pixela = constrain (floor (a), 0, width - 1);
    var pixelb = constrain (floor (b), 0, height - 1);
    var sw = random (0, 0.5); // randomising stroke weight
    var pixelColorLocationXY = Pimg.get (pixela, pixelb);

    strokeWeight (sw); // randomised stroke weight
    fill (pixelColorLocationXY);

    beginShape (); // making a new hexagonal shape
    vertex (a, b);
    vertex (a + 4, b);
    vertex (a + 7, b + 4);
    vertex (a + 5, b + 8);
    vertex (a, b + 8);
    vertex (a - 2, b + 4);
    endShape (CLOSE);

}


For this project, I wanted to develop a somewhat abstract self portrait that is made of hexagonal shapes that appear on screen in a linear fashion.

Project 9: Computational Portrait

sketch

//John Henley; jhenley; 15-104 section D

var img;
var smallPoint;
var largePoint;

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

function setup() {
    createCanvas(331, 442);
    img.resize(img.width/3, img.height/3); //reduce size of image
    print(img.width);
    print(img.height);
    smallPoint = 4;
    largePoint = 40;
    imageMode(CENTER);
    noStroke();
    background(255);
    img.loadPixels();
}

function draw() {
    //Maps mouseX to point size range to pixels
    var pointillize = map(mouseX, 0, width, smallPoint, largePoint);
    //Calculates random pixel generation locations
    var x = floor(random(img.width));
    var y = floor(random(img.height));
    var pix = img.get(x, y);
    //Maps mouseY for to framerate range
    var yframes = map(mouseY, 0, height, 1, 200);
    fill(pix, 128);
    //Draws square pixels
    square(x, y, pointillize);
    //Changes frame rate
    frameRate(yframes);
}

I wanted the interaction on my portrait to be the speed at which the computer builds the portrait. I made this performed using the mouseY value: the user can move the mouse along the y-axis to change the frame rate. I also made it so the mouseX value determines the size of the square pixels used to build the picture.

Appearance of portrait when mouse cursor is at bottom right of canvas.
Appearance of portrait when mouse cursor is at bottom left of canvas.

Portrait

The first thing that came to mind when thinking of portrait is Warhol’s Mao. I radially sampled a portrait of Mao and mapped the sum of each sampled pixel’s red and blue values from 0 to 5, and used that as the size of each dot to make a pop-art-esk halftone effect. I attached a photo because the actual output is too big. Enjoy!!

sketch

var img;
var step = 5;
var rmax = 6;
var xpos = [];
var ypos = [];
var rad = [];

function preload() {
    img = loadImage('https://i.imgur.com/R13OPCr.jpeg');
}


function setup() {
    createCanvas(2*530, 2*670);
    image(img, 0, 0, width/2, height/2);
}


function draw() {
    rectMode(CENTER);
    noStroke();
    var xposNum;
    var yposNum;
    for (var r = 0; r < img.width; r+=step) {
        for (var theta = 0; theta < img.height; theta+=step) {
            xposNum = img.width/2+r*cos(radians(theta));
            yposNum = img.height/2+r*sin(radians(theta));
            var c = get(xposNum,yposNum);
            fill(c);
            xpos.push(xposNum);
            ypos.push(yposNum);

            c = red(c)+blue(c);
            c = map(c, 0, 510, 0, rmax);
            if (xposNum > img.width || yposNum > img.height || xposNum < 0 || yposNum < 0) {
                c = rmax;
            }
            rad.push(rmax - c);
        }
    }

    background(255);

    push();
    for (var i = 0; i < xpos.length; i++) {
        fill('RED');
        ellipse(xpos[i], ypos[i], rad[i]);
    }
    translate(width/2, 0);
    for (var i = 0; i < xpos.length; i++) {
        fill('GREEN');
        ellipse(xpos[i], ypos[i], rad[i]);
    }
    pop();
    push();
    translate(0, height/2);
    for (var i = 0; i < xpos.length; i++) {
        fill('BLUE');
        ellipse(xpos[i], ypos[i], rad[i]);
    }
    pop();
    push();
    translate(width/2, height/2);
    for (var i = 0; i < xpos.length; i++) {
        fill('MAGENTA');
        ellipse(xpos[i], ypos[i], rad[i]);
    }

    noLoop();
}

Project 9: Computational Portrait

sketch

var img;
var diameter;

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

function setup() {
    createCanvas(320, 480);
    image(img, 0, 0, 320, 480);
    background(110);
}

function draw() {
    noStroke();
    x = random(2000);
    y = random(2992);
    c = img.get(x, y);
    fill(c);
    if (x < 1500 & x > 300 && y < 2000 && y > 550) {
        diameter = 10;
    } else {
        diameter = 20;
    }
    circle((x * 0.16), (y * .16), diameter);
}

Project 09 Portrait

sketch

//Tim Nelson-Pyne
//tnelsonp@andrew.cmu.edu
//section C
//Assignment-09-Project



var img;
var x = [];
var y = [];
    



function preload() {
    //loads the walking Images
    img = loadImage('https://i.imgur.com/gCoIwkQ.jpg');
    
}

function setup() {
    createCanvas(480, 480);
    img.resize(width, height);
    background(255);
    img.loadPixels();

    
}




function draw() {
    //ellipse width
    var w = 1;
    //change in ellipse width
    var dw = .8;
    
    for(var row = 0; row < width; row += 5) {
        for (var col = 0; col < height; col +=5) {
            //gets the color of the current pixel location
            var pix = img.get(col, row);
            //generates an inverse color reading of the image
            var invR = 255 - pix[0];
            var invG = 255 - pix[1];
            var invB = 255 - pix[2];
            noStroke();
            fill(invR, invG, invB);
            //draws the inverse image in background
            rect(col, row, 5, 5)
            fill(pix);
            //changes the width of ellipses
            w += dw;
            if (w > 6 || w < 1) {
                dw = - dw;
            }

            ellipse(col, row, w, 6);
        }
    }

    



noLoop();
}

Project 09

I started up by pixelating my photo, then I went into the idea of creating a mirror-like, dynamic, and interactive image. Therefore, I created 1500 moving hexagons to show my image. I am satisfied with the beauty and abstractness.

cody.09project
var img;
var hexagon = []
function preload(){
   img = loadImage("https://i.imgur.com/VGvokSI.png");
}
//making a hexagon
function makeHexagon(cx, cy, cdx, cdy) { 
    var h = {x: cx, y: cy, dx: cdx, dy: cdy,
            drawFunction: drawHexagon
        }
    return h;
}
function drawHexagon(){
    push()
    translate(this.x,this.y)
//hexagon color is the color of the pixel it is at
    this.c = img.get(10*this.x,10*this.y)
    fill(this.c)
//draws the hexagon from 6 triangles
    noStroke()
    triangle(0,0,-s,0,-s/2,-s*sqrt(3)/2)
    triangle(0,0,-s/2,-s*sqrt(3)/2,s/2,-s*sqrt(3)/2)
    triangle(0,0,s,0,s/2,-s*sqrt(3)/2)
    triangle(0,0,-s,0,-s/2,s*sqrt(3)/2)
    triangle(0,0,-s/2,s*sqrt(3)/2,s/2,s*sqrt(3)/2)
    triangle(0,0,s,0,s/2,s*sqrt(3)/2)
//hexagons would bounce backs if touches the edges
    if (this.x >= width || this.x <= 0){
        this.dx = -this.dx
    }
    if (this.y >= height || this.y <= 0){
        this.dy = -this.dy;
    }
    this.x += this.dx;
    this.y += this.dy;
    pop()
}
function setup() {
    createCanvas(480,480);
    img.resize(4800,4800)
//make 1500 hexagons explode outwards from my left eye, pushed into array
    for (var i = 0; i < 1500; i++) { 
        hexagon[i] = makeHexagon(random(255,260),random(230,250),random(-4,4),random(-4,4))
    }
    text("p5.js vers 0.9.0 test.", 10, 15);
}
var s = 14
function draw() {
    background(200)
    image(img,0,0,480,480)
//pixelated because having a clear image of my huge face on wordpress is horrifying
    for(var x = 0; x < width; x += 10){ 
        for(var y = 0; y < height; y += 10){
            var c = img.get(10*x,10*y);
            fill(color(c));
            noStroke();
            rect(x,y,10,10);
        }
    }
//draw 1500 hexagons
    for (var i = 0; i < 1500; i++) { 
        hexagon[i].drawFunction() 
    }
}