Project_09_Portrait

My portraitDownload
//Huijun Shen
//huijuns@andrew.cmu.edu 
//section D

var imgFace;

 
function preload(){
    
    imgFace = loadImage("https://i.imgur.com/d3YOxlo.jpg"); 


}

function setup(){
    createCanvas(480,480);
   // imageMode(CENTER);
    imgFace.loadPixels();
    imgFace.resize(480,480);
    noStroke();
    frameRate(200);


}

function draw(){

    //image(imgFace,0,0,width,height);

    var xp = floor(random(imgFace.width));
    var yp = floor(random(imgFace.height));
    var pix = imgFace.get(xp,yp);
    fill(pix);
    print(pix);
    push();
    translate(xp,yp);
    Orthotomic();
    pop();

    
    

}

function Orthotomic(ex,ey){ // Here is the code I reused from my previous work and I made some changes to it so that it fit this painting better.


        var nPoints = 100;

        var x,y;

        beginShape(); // the shape
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        x = constrain(mouseX,0,150)/30*cos(t); //the shape size is affected by mouseX
        y = sin(t);
        var x1 =x*cos(2*t)-y*sin(2*t)+2*sin(t);
        var y1 =-x * sin(2*t) - y*cos(2*t) + 2*cos(t);
        vertex(x1+random(5), y1+random(5)); //make the edge a bit random lines
    }


    endShape(CLOSE);

}

In this project, I customized the shape of the “Brush” a bit by reusing previous and made it a bit randomized. The edge of the brush is changing every frame. The size of the brush is controlled by MouseX so that painter can do big stroke at the very beginning and small stroke at the very end to put more details.

Leave a Reply