jennyzha – Project 09

sketch

// Jenny Zhang
// jennyzha
// Section D
// Project 09

var jennyzha;

function preload() {
    var Image = "https://i.imgur.com/c3AjAad.jpg";
    jennyzha = loadImage(Image);
}

image(jennyzha);

function setup() {
    createCanvas(480, 480);
    background(0);
    jennyzha.loadPixels();
    frameRate(10);
}

function draw() {
    var px = random(width);
    var py = random(height);
    var ix = constrain(floor(px), 0, width-1);
    var iy = constrain(floor(py), 0, height-1);
    var ColorXY = jennyzha.get(ix, iy);

    push();
    stroke(ColorXY);
    strokeWeight(1);
    line(px, py, px, py + 30); 
    pop();

    stroke(ColorXY);
    strokeWeight(1);
    line(mouseX, mouseY, mouseX, mouseY + 30); 
}

This project took me a lot of trial and error, interestingly enough, not because of the code but because of imgur and the image itself. First, after seeing that my code would not load, and feeling fairly confident in my code itself, I realized that I had used the wrong url for the image on imgur. Second, after the code started to run the way I wanted it to, I saw that it was loading just the background. This is when I realized that it was because the image was over 1000X1000 pixels and my canvas was only the max requirement, 480X480. I quickly went back to the original image, shrunk it down and the code worked perfectly.

Leave a Reply