sntong-Project-09-Portrait

sketch

// Scarlet Tong
// sntong@andrew.cmu.edu
// Section A
// Project 09 - Computational Portrait (Custom Pixel)

// variable to store the image
var pic;

function preload(){
  // load image into variable
  pic = loadImage("https://i.imgur.com/fLLh0am.jpg")
}

function setup(){
  createCanvas (280,480);
  imageMode(CENTER);
  background(255);
}

function draw(){
  // extract pixes from image
  pic.loadPixels();
  // select random x and y values to generate the "cross"
  var x = floor(random(pic.width));
  var y = floor(random(pic.height));
  // extract color from that pixel
  var pixCol = pic.get(x, y);
  //set stroke color to color of the pixel
  stroke(pixCol);
  // distance to allow to draw ther lines to form a cross
  var dis = random(10);
  // draw crosses
  line(x,y,x+dis,y+dis);
  line(x,y+dis,x+dis,y);
  // create small cicles that are located at the center of the crosses
  fill(pixCol);
  ellipse(x+(dis/2)+0.5, y+(dis/2)+0.5,dis/3,dis/3);
}

I decided to make a pixel that is a cross with a dot in the middle, which I will use to trace a self portrait of myself. I used random to select where every new pixel is drawn to create the image.

Portrait generated from code

Leave a Reply