Project 09: Computational Portrait

I created my self-portrait using different symbols that are linked to the pixel colors on the image. When the mouse is pressed, the shapes are drawn to create the image.

sketch
//amy hu
//amyhu
//section d

var img;
var smallPoint, largePoint;
var symbols = ["❀", "❋", "✯"]

function preload() {
    img = loadImage('https://i.imgur.com/2ZzOdG6.png');
}

function setup() {
    createCanvas(450,450);
    // smallPoint = 5;
    // largePoint = 20;
    imageMode(CENTER);
    noStroke();
    background(255);
    img.loadPixels();
}

function draw() {
    //mouse location determines point size
    var pointillize = map(mouseX, 0, width, smallPoint, largePoint);

    //picks random x y value
    var x = floor(random(img.width));
    var y = floor(random(img.height));

    //gets pixel color form a xy value
    var pix = img.get(mouseX, mouseY);

    //fills pixel color
    fill(pix, 128);
    ellipse(x, y, pointillize, pointillize);

    //draws symbols when mouse is pressed 
    if(mouseIsPressed){
        textSize(random(10,35));
        text(random(symbols), mouseX, mouseY);
    }
}

Project – 09: Portrait

Using pointillism for different shapes. Before, I was trying to use different lines, but I wasn’t able to get it to work sadly.

sketch
After 1 minute
After 2 minutes
After 5 minutes
var sonia;
var smallPoint, largePoint;

function preload() {
    sonia = loadImage("https://i.imgur.com/3h0u1wQ.jpeg");
}
function setup() {
    createCanvas(480, 480);
    //creating variables for the smallPoint size and the largePoint size
    smallPoint = 4;
    largePoint = 20;
    noStroke();
    background(220);
    rectMode(CENTER)
}

function draw() {
    //created 6 x and y variables to hold different sizes of widths and heights based on the corresponding variable
    var x1 = floor(random(sonia.width));
    var y1 = floor(random(sonia.height));
    //-10 and +10 so that it would always draw a shorter line, so when I used get, it would get a color closer to the point.
    var x2 = floor(random(x1 - 10, x1 + 10));
    var y2 = floor(random(y1 -10, y1 + 10));
    var x = floor(random(sonia.width));
    var y = floor(random(sonia.height));
    var lineLength = ((y2 - y1) / (x2 - x1)) / 10;
    createMultipleLines(x1,y1, x2,y2);
    createMultipleRectangles(x,y);
    createMultiplePoints(x,y);
}

function createMultipleLines(x1, y1, x2, y2) {
    var pointillize = map(mouseX, 0, width, smallPoint, largePoint);
    //gets color
    var pix = sonia.get(x1,y1);
    var pix1 = sonia.get(x2,y2);
    stroke(pix);
    //random strokeWeight
    strokeWeight(random(0.1, pointillize));
    line(x1,y1,x2,y2);
}

function createMultipleRectangles(x,y) {
    //creates multiple rectangles using same method
    var pointillize = map(mouseX, 0, width, smallPoint, largePoint);
    print(sonia.width);
    print(sonia.height)
    var pix = sonia.get(x,y);
    fill(pix);
    noStroke();
    rect(x,y, pointillize, pointillize);
}

function createMultiplePoints(x,y) {
    //creates multiple circular points using same method.
    var pointillize = map(mouseX, 0, width, smallPoint, largePoint);
    print(sonia.width);
    print(sonia.height)
    var pix = sonia.get(x,y);
    fill(pix);
    noStroke();
    ellipse(x,y, pointillize, pointillize);
}
    


// function createTinyLines(x1,y1,x2,y2, lineLength) {
//     var pointillize = map(mouseX, 0, width, smallPoint, largePoint);
//     for (var i = 0; i< lineLength; i ++) {
//         var pix = sonia.get(x1,y1);
//         var pix1 = sonia.get(x2,y2);
//         stroke(pix);
//         line(x1,y1,x2,y2);
//         var slopeY = y2 - y1;
//         var slopeX = x2 - x1;
//         x1 = x2;
//         y1 = y2;
//         x2 += slopeX;
//         y2 += slopeY;
//     }
// }

// function createOneLine(x1,y1,x2,y2, lineLength) {
//     //var pointillize = map(mouseX, 0, width, smallPoint, largePoint);
//     var pix = sonia.get(x1,y1);
//     var pix1 = sonia.get(x2,y2);
//     stroke(pix);
//     for (var i = 0; i< 20; i ++) {
//         line(x1,y1,x2,y2);
//         var slopeY = y2 - y1;
//         var slopeX = x2 - x1;
//         x1 == x2;
//         y1 == y2;
//         x2 += slopeX;
//         y2 += slopeY;
    
//     }
    
// }

Project 09: Computational Portrait (Custom Pixel)

i used my portrait as an each pixel to create a whole portrait. I used smaller images for face & background section, but bigger and rotated images for hair and eye section to separate the section of my feature.

sketchDownload
// Alicia Kim
// yoonbink
// Section B

function preload(){ //load the image
    alicia = loadImage("https://i.imgur.com/FPEjcyO.jpeg");
}


function setup() {
    createCanvas(480, 480);
    imageMode(CENTER);
    angleMode(DEGREES);
    background(220);
    alicia.resize(480,480); //resize alicia to canvas size
    alicia.loadPixels(); //load pixels
}

function draw() {
    var x = floor(random(alicia.width)); //random x-coordinate value
    var y = floor(random(alicia.height)); //random y-coordinate value
    var pixColor = alicia.get(x,y); //get random coordinate in the canvas
    tint(pixColor); //tint with the color of that coordinate 

// divide sections by hair and the rest

    if (pixColor[0]>130) { //face & background has smaller images
        image(alicia,x,y,9,9);
    }

    if (pixColor[0]<130) { //hair section has bigger & rotated images 
        push();
        translate(x,y);
        rotate(180);
        image(alicia,0,0,13,13);
        pop();   
    }
}

Project 9 – Portrait

What is Beauty?

sketch – Copy – Copy – Copy
// Ana Furtado 
// Section E
// Project 9 Computational Portrait
//What is Beauty?

let img;
let smallPoint;
let largePoint; 

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

function setup() {
    createCanvas(480, 480);
    smallPoint = 10;
    largePoint = 15;
    img.resize(width, height);
    imageMode(CENTER);
    background(255);
    noStroke(); 
    img.loadPixels();
    frameRate(75);
}


function draw() {
    //paint the image using dots
    let point = map(mouseX, 0, width, smallPoint, largePoint);
    let x = floor(random(img.width));
    let y = floor(random(img.height));
    let pix= img.get(x,y);
    fill(pix, 128);
    //fill(pix);
    ellipse(x, y, point, point);

    //prints What is Beauty? across canvas in random places using image colors
    wordtext = ["What", "is", "Beauty?"];
    for (var i = 0; i <3; i++) {
        fill(pix);
        textSize(random(1,15));
        text(wordtext[floor(random(wordtext.length))], random(0,width), random(0,height));
        //floor gives less messages than round
    }

    //paints/ further distorts image using randomly placed line of image color 
    push();
    stroke(pix);
    let a = random(0,width);
    let b = random(0,height);
    line(a, b, a+10, b+10);
    //line(a, b+10, a+10, b);
    pop();
}

    
    

The most challenging part of this project was making all the different elements work to distort the existing image to create a new portrait.

Project 09: Computational Portrait (Custom Pixel)

Click to switch between “circles” or “lines” mode.

“Circles” Mode: move the mouse left or right to change the circles’ size and stroke weight to make the portrait more blurry.

“Lines” Mode: move the mouse left or right to change the rotation angle of the lines to create the wind blowing effect.

sketch
Circles
Lines
//Xinyi Du 
//15104 Section B
//xinyidu@andrew.cmu.edu
//Assignment-09

//Click to switch between "circles" or "lines" mode.

//"Circles" Mode: 
//move the mouse left or right to change the circles' size and stroke weight 
//to make the portrait more blurry.

//"Lines" Mode: 
//move the mouse left or right to change the rotation angle of the lines 
//to create the wind blowing effect.

var click = 0; //number of clicks

function preload() {
  
  img = loadImage("https://i.imgur.com/ncc1zMh.jpg");
  //original url https://i.imgur.com/mOmrZEo.jpg
}

function setup() {
  createCanvas(547, 547);
  background(255);
  imageMode(CENTER);
  img.loadPixels(); //load pixels
}

function draw() { 
  //click to switch between "circles" or "lines" mode
  if (click % 2 == 0) {
    draw1(); //circles mode
  }
  else {
    draw2(); //lines mode
  }
}


function draw1() { //circles
  for (i=0; i<100; i++) {
    var x = floor(random(img.width)); //random x of the center of circles
    var y = floor(random(img.height)); //random y of the center of circles
    var dotcolor = img.get(x, y); //get the pixel color info
    var point = (dotcolor[0]+dotcolor[1]+dotcolor[2])/3; //get the average RGB value

    //map the mouseX position to circle sizes
    var mapsize = map(mouseX, 0, width, 5, 30);
    //map the mouseX position to circle stroke weights
    var mapWeight = map(mouseX, 0, width, 5, 0.5);;

    strokeWeight(mapWeight);
    stroke(dotcolor); //strokecolor is the pixel color
    noFill();
    ellipse(x, y, mapsize, mapsize);
    stroke(dotcolor[0]+35, dotcolor[1]+35, dotcolor[2]+35); //stroke color ligher
    ellipse(x, y, mapsize*1.5, mapsize*1.5); //circle size bigger
    stroke(dotcolor[0]-35, dotcolor[1]-35, dotcolor[2]-35); //stroke color darker
    ellipse(x, y, mapsize*0.5, mapsize*0.5); //circle size smaller
  }
}


function draw2() { //lines
  for (i=0; i<10000; i++) {
    var initdegree = mouseX; //mouseX determines the initial degree
    //x, y of the starting point of the lines, random points within the canvas
    var x = floor(random(img.width)); 
    var y = floor(random(img.height));
    var dotcolor = img.get(x, y);
    var point = (dotcolor[0]+dotcolor[1]+dotcolor[2])/3;

    //map the average RGB value to degrees, the greater the value the greater the degrees
    var mapdegree = initdegree+map(point, 0, 255, 0, 180);
    //map the average RGB value to line lengths, the greater the value the shorter the lengths
    var maplength = map(point, 0, 255, 15, 2);
    //map the average RGB value to stroke weights, the greater the value the smaller the stroke weights
    var mapWeight = map(point, 0, 255, 5, 0.3);

    noFill();
    strokeWeight(mapWeight);

    push();
    translate(x,y); //translate the origin to (x,y)
    rotate(radians(mapdegree)); //rotate mapdegree
    stroke(dotcolor);
    line(0, 0, 0+maplength, 0+maplength);
    stroke(dotcolor[0]+35, dotcolor[1]+35, dotcolor[2]+35);
    line(10, 0, 10+maplength+5, 0+maplength+5);
    stroke(dotcolor[0]-35, dotcolor[1]-35, dotcolor[2]-35);
    line(-10, 0, -10+maplength-5, 0+maplength-5); 
    pop();
  }

}

function mousePressed() {
  click ++ ; //if mouse is pressed, increase number of clicks
}


Project 9 portrait

sketch
//Evette LaComb 
//Section D 
//09 project 


//the portrait must be an un-retouched photograph of a person
//that can be acessed on imgur.com 
//you can only display the portrait generated
//should not be bigger than 480 x 480
//show creativity 
//write a sentance or tow reflecting on your process and product 


let img;
var x; 
var y;

var angle = 0;
var radius = 0;
var frameCount = 0;
var circleSize = 1;

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

function setup() {
  createCanvas(480, 480);
  img.loadPixels();
  imageMode(CENTER);
  img.resize(480, 480)
  background("grey");

  noStroke();

}

function draw() {

    //varaibles for x and y occording to spiral 

    x = radius * cos(radians(angle));
    y = radius * sin(radians(angle));

    //code for calling pixels: 


   var pix = img.get(x, y);
   var pixx = img.get(width/2, y);

   //code for the circels and fill:


    fill(pix);
    circle(x, y, circleSize);
    fill(pixx);
    circle(x, y, circleSize/2);

    //code for the spiral:

    radius += frameCount / 3000;
    angle += 8;
    frameCount += 1;
    circleSize += 0.07;
    if (frameCount > 3000) {
        noLoop();
    }

    //border to cover where circles could not be drawn:

    fill("white");
    rect(0, 0, width, 20);
    rect(0, height - 20, width, height - 20);
    rect(0, 0, 20, height);
    rect(height - 20,0,  height, width- 20);

}

//my process for this was I wanted to include a spiral effect revealing the image
//I found that translating th spiral to the center effted where my pixel colors were being grabbed from
//I changed the spiral instead to start at 0, 0
//I ended up liking this effect better because it shows how the that top corner 
//is the brightest part. The spiral created a sun ray effect that looked cool
//I then wanted something else in the circled so I made donuts with the 
//inverted color in the center. This helped to bring some color to the top corner
//so it wasnt just all white.



Project-09

I tried to use random quadrangles and words to construct a self portrait. And the words I use are the place I was born, grown up and the place i’m staying.

sketch
var img;
var words = ['Beijing', 'Kunming', 'Pittsburgh','Alice']
var number = 1;

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

function setup() {
    createCanvas(400, 480);
    //resize image to fit canvas
    img.resize(width, height);
    frameRate(400);

    imageMode(CENTER);
    noStroke();
    background(255);
    img.loadPixels();
}

//draw image
function draw() {
    if(number==1) {
        drawWord();
    } else {
        drawPolygon(); 
    }
  
} 

function drawPolygon() {
    var x = floor(random(img.width));
    var y = floor(random(img.height));

    //picking color
    var pix = img.get(x, y);
    fill(pix, 128);

    //draw the random shape
    beginShape();
    vertex(x,y);
    vertex(x-(random(4,7)), y+(random(10, 25)));
    vertex(x-(random(4,7)), y+(random(25, 40)));
    vertex(x,y+(random(40, 60)));
    vertex(x+(random(4,7)), y+(random(25, 40)));
    vertex(x+(random(4,7)), y+(random(10, 25)));
    endShape();
    
}

function drawWord() {
    var x = floor(random(img.width));
    var y = floor(random(img.height));

    var pix = img.get(x, y);
    fill(pix, 128);
    textSize(random(3,15))

    //randomly pick words to draw
    text(words[int(random(0,4))], x, y)
}

function mousePressed() {
    //changing between two options
    number++;
    if(number > 2) {
      number = 1
    }
    background(255)
}

random quad portrait

this sketch samples pixel colors and draws random quadrilaterals where the pixel was sampled from. mouseX controls the size of the shapes, while pressing the mouse will fill the shapes, rather than using the color as a stroke. press a key to erase the canvas.

below are some earlier variations in which I manually changed the size and fill/stroke boolean, and tested out density using a loop. (this version was not interactive).

sketch
// jaden luscher
// jluscher@andrew.cmu.edu
// section a
// project 09

// initially i had tried making a chuck close-style portrait with a pixel matrix,
// then i shifted to funky shapes instead. the ineraction was added at the end
// when i kept wanting to tweak the size and fill/stroke modes.

var jaden;    // original image
var x1;
var y1;
var dx = 0;   // noise step
var dy = 0;
var size;    // bounds of shape
var yesFill = false;

function preload() {
    jaden = loadImage("https://i.imgur.com/BRUtdb2.png")  // original portrait
}

function setup() {
    createCanvas(400, 400);
    background(0);
    frameRate(60);
    jaden.loadPixels();
}

function draw() {
    size = int(map(constrain(mouseX, 0, width), 0, width, 5, 50));
    if (mouseIsPressed) {   // toggle fill mode
        yesFill = true;
    } else {    // reset to line drawing mode
        yesFill = false;
    }
    if (keyIsPressed) {   // erase drawing
        background(0);
    }
    drawShape();
    print(yesFill);
}

function drawShape() {
    x1 = int(map(noise(dx), 0, 1, -150, width + 150));
    y1 = int(map(noise(dy), 0, 1, -150, height + 150));
    dx += random(0.1, 1.0);
    dy += random(0.1, 1.0);

    if (yesFill == true) {
        noStroke();
        fill(jaden.get(x1, y1));    // returns pixel from canvas
    } else if (yesFill == false) {
        strokeWeight(1);
        stroke(jaden.get(x1, y1));    // returns pixel from canvas
        noFill();
    }
    beginShape(QUADS);   // generate random polygons
    vertex(random(-1 * size, size) + x1, random(-1 * size, size) + y1);
    vertex(random(-1 * size, size) + x1, random(-1 * size, size) + y1);
    vertex(random(-1 * size, size) + x1, random(-1 * size, size) + y1);
    vertex(random(-1 * size, size) + x1, random(-1 * size, size) + y1);
    endShape();
}

Project 09: Portrait

sketch

//Name: Hari Vardhan Sampath
//Section: E
//eMail address: harivars@andrew.cmu.edu
//Project-09

// global variable to store the preloaded image
var img;

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

/* 
Reference from lecture-20's random bouncing particles.
The bouncing particles will draw the image by accessing
the pixel colors it traverses.
Additionally, the mouseY position will control the alpha
of the pixel color and the mouse click will reset the background
to different grey color, also using the mouseY position
for the user to play with the abstract representation.
*/

// number of particles
var np = 100;  

function particleStep() {
    this.age++;
    this.x += this.dx;
    this.y += this.dy;
    if (this.x > width) { // bounce off right wall
        this.x = width - (this.x - width);
        this.dx = -this.dx;
    } else if (this.x < 0) { // bounce off left wall
        this.x = -this.x;
        this.dx = -this.dx;       
    }
    if (this.y > height) { // bounce off bottom
        this.y = height - (this.y - height);
        this.dy = -this.dy;
    } else if (this.y < 0) { // bounce off top
        this.y = -this.y;
        this.dy = -this.dy;
    }
}


function particleDraw() {
    this.clr = img.get(this.x, this.y);
    stroke(this.clr[0], this.clr[1], this.clr[2], mouseY);
    point(this.x, this.y);
}


function makeParticle(px, py, pdx, pdy) {
    p = {x: px, y: py,
         dx: pdx, dy: pdy,
         age: 0,
         stepFunction: particleStep,
         drawFunction: particleDraw
        }
    return p;
}


var particles = [];


function setup() {
    createCanvas(img.width, img.height);
    background(mouseY);
    for (var i = 0; i < np; i++) {
        var p = makeParticle(600, 600,
                             random(-10, 10), 
                             random(-10, 10));
        particles.push(p);
    }
    frameRate(15);
}


function draw() {
    strokeWeight(random(5));
    for (var i = 0; i < np; i++) { 
        var p = particles[i];
        p.stepFunction();
        p.drawFunction();
    }
}

// mouse press will refresh the background to re-draw
function mousePressed() {
  background(mouseY);
}

Project 09 : Computational Portrait

The Image is based on how Octopus uses their camouflage:

So Basically I created a bunch of particles that ages and disappear eventually:

when those particles first appear they growth rapidly then they slowly shrink and fade away

Base Image:

Base Image

/*
 * Andrew J Wang
 * ajw2@andrew.cmu.edu
 * Section A
 *
 * This Program is Face
 */

//face image for preload the data
let faceImage;
//array of global particles
var particles = [];

//preload image
function preload(){
    faceImage = loadImage("https://i.imgur.com/i3WmsKd.jpeg");
}


function particleStep() {
    //age of the particles 
    this.age++;

    //shrine slowly after 45 age
    if (this.age % 2 == 0 & this.age >= 45)
        {
            this.sz = this.sz * 0.98;
        }
    //grow rapidly before 45 age
    else if (this.age % 2 == 0 & this.age < 45)
        {
            this.sz = this.sz * 1.1;
        }

}
 
 
function particleDraw() {
    push();
    //grab color based on the location on the image
    var kolor = faceImage.get(this.x*2, 220+this.y*2);
    fill(kolor);
    noStroke();
    rectMode(CENTER);
    //create rectangle based on location size and color
    rect(this.x, this.y, this.sz, this.sz);
    pop();
}
 

//create color particles
function makeParticle(px, py, size) {
    p = {x: px, y: py,
         age: 0,
         sz: size,
         stepFunction: particleStep,
         drawFunction: particleDraw
        }
    return p;
}
 
 
function setup() {
    createCanvas(480,480);
    frameRate(120);
}


function draw() {
    background(220);
    stroke(0);

//create 30 particles per fram just to fill the whole image with particles
    for (var n=0; n<30; n++)
    {
        //create particles at random location on the canvas, origin size = 1
        var p = makeParticle(random(480), random(480),1);
        particles.push(p);
    }

    //new particles to refresh
    newParticles = [];
        for (var i = 0; i < particles.length; i++){ // for each particle
        var k = particles[i];
        //draw and refresh particles
        k.stepFunction();
        k.drawFunction();
        if (k.age < 250) {
            //if younger than 250 keep them if not they are gone
        newParticles.push(k);
        }
    }
        // particles refreshed by the new particles
        particles = newParticles;

}