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);
}

Leave a Reply