Project-09 Portrait

project
let portrait;
var radius = 0;
var angle = 0;
var framecount = 1;
var size = 0.5;

function preload() {
  portrait = loadImage('https://i.imgur.com/EquKB8x.png');
}

function setup() {
  createCanvas(480, 480); 
  background(0);
  imageMode(CENTER);
  portrait.loadPixels();
}

function draw() {
  var centerX = width/2;
  var centerY = height/2;
  var circleX = radius * cos(radians(angle));
  var circleY = radius * sin(radians(angle));

  var clrX = random(0, width);
  var clrY = random(0, height);
  var clr = portrait.get(clrX, clrY);

  //pointillize 
  for (var i= 0; i < 10; i++) {
    fill(clr);
    circle(clrX, clrY, size);
  }

  //top left spiral of hearts of image 
  noStroke();
  var clr1 = portrait.get(circleX, circleY);
  fill(clr1);
  drawHeart(circleX, circleY, 15);

  //bottom right spiral of hearts of image 
  push();
  translate(centerX, centerY);
  var clr2 = portrait.get(480-circleX, 480-circleY);
  fill(clr2);
  drawHeart(centerX-circleX, centerY-circleY, 15);
  pop();

  topInstagramBar();
  bottomInstagramBar();

  radius += 0.1;
  angle += 7;

  frameCount += 1;
  if (frameCount > 13000) {
    //"instagram tag" of my nickname where mouse is 
    fill(85);
    triangle(mouseX, mouseY-10, mouseX+10, mouseY-20, mouseX-10, mouseY-20);
    rect(mouseX-40, mouseY-40, 80, 20);
    fill(255);
    text('rishdish', mouseX-20, mouseY-27);

    //stops when portrait is complete
    noLoop();
  }
}

function drawHeart(x, y, s) {
  beginShape();
  vertex(x,y);
  bezierVertex(x-s/2, y-s/2, x-s, y+s/3, x, y+s);
  bezierVertex(x+s, y+s/3, x+s/2, y-s/2, x, y);
  endShape(CLOSE);
}

function mousePressed() {
  //points get bigger as you click 
  size += 0.5;
  if (size == 7) {
    size = 0.5;
  }
}

function topInstagramBar() {
  //instagram bar 
  fill(240);
  rect(0, 0, 480, 30);

  //profile pic 
  fill(230, 210, 210);
  circle(20, 15, 15);
  stroke(195, 45, 140);
  noFill();
  circle(20, 15, 18);
  noStroke();
  fill(0);
  text('15-104',35, 19);

  //three dots in right hand corner
  fill(10);
  circle(455, 15, 3);
  circle(460, 15, 3);
  circle(465, 15, 3);
}

function bottomInstagramBar() {
  //instagram bar 
  fill(240);
  rect(0, 450, 480, 30);
  
  //"like" icon
  stroke(0);
  fill(255);
  drawHeart(20, 460, 15);
  
  //"comment" icon
  triangle(53, 471, 60, 471, 58, 467);
  circle(50, 465, 16);
  stroke(255);
  circle(55, 468, 5);

  //"share" icon
  stroke(0);
  triangle(75, 457, 92, 457, 80, 463);
  triangle(80, 463, 92, 458, 82,472);

  //"save"icon
  beginShape();
  vertex(454, 457);
  vertex(454, 472);
  vertex(460, 467);
  vertex(466, 472);
  vertex(466, 457);
  endShape(CLOSE);

  //image scroll through icons
  noStroke();
  fill(65, 141, 204);
  circle(230, 465, 5);
  fill(165);
  circle(240, 465, 5);
  circle(250, 465, 5);
}

Start of portrait/halfway completed portrait
Completed portrait

I used a photo of me as a baby for this. Once I had the two spirals of hearts running, I added the icons to make it look like an instagram post. When you click, the size of the points in the background increases. When the portrait is done running, an Instagram tag shows up where the mouse is with my childhood nickname.

Project 9: Portrait

I really wanted to implement a little bit of what we did two weeks ago, so I created a heart and infinity code, and used those as pixels. I have four different “portraits” each time the mouse is clicked. The first one randomly draws hearts and draws the text “This Is Me” with your cursor. The second one randomly draws the text “Sarah” and draws infinity signs with you cursor. The third one randomly draws infinity signs and draws the text “This Is Me” with your cursor. The fourth one randomly draws random sizes from 10 to 25 of the text “Sarah” and draws infinity signs with you cursor. Additionally, every click increases (to a certain number) sizes of all the pixels, and changes the transparency of the background and decreases (to a certain number), going back and forth between the two.

sketch.slslslDownload
// Sarah Luongo   
// sluongo
// sluongo@andrew.cmu.edu
// Project

// This code aims to draw a self-image with pixels.

var oI; // 'Original image'
var nP = 1; // 'New portrait'
var t = 210; // 'Transparency'
var tS = 10; // 'Text size'
var hS = .3; // 'Heart size'
var iS = 15; // 'Infinity size'
incT = 51; // Variable to increase size of transparency
incH = .1; // Variable to increase size of hearts
incIT = 1; // Variable to increase size of texts and infinity sign

// Loads image
function preload() {
    var ImageURL = "https://i.imgur.com/UJthwzP.jpg";
    oI = loadImage(ImageURL);
}

function setup() {
    createCanvas(480, 480);
    oI.resize(width, height); // Resizes original image
    background(59, 17, 21, t); // Redish
    oI.loadPixels();
    frameRate(60); // Rate pixels are drawn
    t = 0;
}

function draw() {
    // Generates random locations for the pixels within image size 
    var pX = floor(random(oI.width));
    var pY = floor(random(oI.height));
    var cP = oI.get(pX, pY); // 'Color picker' based on location of pixel
    var cM = oI.get(mouseX, mouseY); // Color selected based on mouse location
    noStroke();

    if (nP == 1) {
        // Draws heart pixels randomly
        fill(cP);
        heart(pX, pY);
        // Draws text pixels w/ cursor
        fill(cM);
        textSize(tS);
        text("This Is Me", mouseX, mouseY);
    } else if (nP == 2) {
        fill(cP);
        textSize(tS);
        text("Sarah", pX, pY);
        fill(cM);
        infinity(mouseX, mouseY);
    } else if (nP == 3) {
        fill(cP);
        infinity(pX, pY);
        fill(cM);
        textSize(tS);
        text("This Is Me", mouseX, mouseY);
    } else {
        fill(cP);
        textSize(random(10, 25));
        text("Sarah", pX, pY);
        fill(cM)
        heart(mouseX, mouseY);
    }	
}

// Heart Curve
// https://mathworld.wolfram.com/HeartCurve.html
function heart(pX, pY) {
    var da = .01; // How round the "curve" is
    // Creates the heart curve
    beginShape();
    for (var t = 0; t <= TWO_PI; t += da) {
        // The parametric equations found on the website commented above
        var x = (16*(pow(sin(t), 3))) * hS;
        var y = (13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)) * -hS;
        vertex(x+pX, y+pY);
    }
    endShape();
}

// Infinity Curve
// https://en.wikipedia.org/wiki/Lemniscate_of_Bernoulli
function infinity(pX, pY) {
    var da = .01;
    // Creates the infinity curve
    beginShape();
    for (var t = 0; t <= TWO_PI; t += da) {
        // The parametric equations found on the website commented above
        var x = (iS*cos(t))/(1+(pow(sin(t), 2)));
        var y = (iS*sin(t)*cos(t))/(1+(pow(sin(t), 2)));
        vertex(x+pX, y+pY);
    }
    endShape();
}

function mousePressed() {
    if (nP == 4) {
        clear();
        background(59, 17, 21, t);
        nP = 1;
    } else {
        clear();
        background(59, 17, 21, t);
        nP += 1;
    }
    // Increase size of each pixel symbol
    t += incT;
    tS += incIT;
    hS += incH;
    iS += incIT;
    // Decrease size after certain point
    if (t == 255 || tS == 30 || hS == 1.5 || iS == 30) {
        incT *= -1;
	incH *= -1;
	incIT *= -1;
    } if ( t == 1 || tS == 10 || hS == .3 || iS == 15) {
	incT *= -1;
	incH *= -1;
	incIT *= -1
    }
}
First portrait at 1 minute w/o drawing w/ cursor
After a minute using cursor
After 30 secs w/ cursor