// Kyle Leve
// kleve@andrew.cmu.edu
// Section A
// Project-09-Portrait
var img;
function preload() {
var myImage = "https://i.imgur.com/lsBIvvW.jpg"; // Variable for image
img = loadImage(myImage); // Loads image
}
function setup() {
createCanvas(480, 480);
background(220);
img.loadPixels(); // Calls image
imageMode(CENTER);
frameRate(500);
}
function draw() {
var x = constrain(floor(random(width)), 0, width-1); // Randomizes x position of pixels
var y = constrain(floor(random(height)), 0, height-1); // Randomizes y position of pixels
noStroke();
var clr = img.get(x, y); // Gets colors from image for pixels
fill(clr);
rect(x, y, 10, 10); // Draws image using rectangles
}
I found this project to be really fun because it allowed me to apply something from my life into my code. The image that is being created is of my friend Sara in hot dog costume while we were taking a trip to target. The one problem I faced was originally the image was too big so only a quarter of the image was being displayed. However, I went back to the image and edited it to a smaller size and that fixed the issue.
Original image
Nearly completed replication