Project 9

This project is fun to create. I decided to use little hearts to paint a portrait. To paint: press the mouse and drag. You can change to a smaller brush size by holding any key.

sketch
it will take you a few minutes to paint. This is a combination of smaller hearts and bigger hearts.
//Jenny Wang
//Section B
//jiayiw3@andrew.cmu.edu
//Project 09

var img;

function preload(){
    img = loadImage("https://i.imgur.com/MBJZ7t1.jpg");
}

function setup() {
    createCanvas(480, 480);
    imageMode(CENTER);
    noStroke();
    background("orange");
    frameRate(50);
}

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

function draw() {
    
    //area radius for random pixels
    var xPosition = random(-5,5);
    var yPosition = random(-5,5);

    //set area for mouse
    var x = map(mouseX,0,width,0,1200); 
    var y = map(mouseY,0,height,0,1500); 

    //get the size of the pixel
    var pixelSize;

    //get the color of the pixel
    var pixC = img.get(x,y);
    

    //set to paint with mouse
    if(mouseIsPressed){
        push();
        translate(mouseX,mouseY);
        fill(pixC);

        //set heart shaped brush with different sizes
        if(keyIsPressed){
            pixelSize = random(4,8);
        }
        else{
            pixelSize = random(10,22);
        }
        heart(xPosition,yPosition,pixelSize);
        pop();
    }
}
    

Leave a Reply