Shirley Chen – Project 04 – String Art

sketch

// Shirley Chen
// Section B
// junfanc@andrew.cmu.edu
// Project-04




function setup() {
    createCanvas(400, 300);
    background(244, 217, 166);

}

function draw() {
    var x1 = 0;
    var y1 = 0;
    var x2 = 0;
    var x3 = 0;
    var y3 = 0;

    strokeWeight(1);
    //Draw the blue lines at the bottom left corner
    for (var i = 0; i < 50; i++){
        y1 += 4;
        x1 += 8;
        stroke(166, 188, 201);
        line(0, y1, x1, height);
    }
    //Draw the yellow and pink lines at the upper left and right corner
    for (var i = 0; i < 50; i++){
        x2 += 20;
        x3 += 5;
        y3 += 5;
        stroke(242, 143, 143);
        line(400, 0, x2, height);
        stroke(255, 191, 62);
        line(x3, 0, x3, y3);
    }
    strokeWeight(1);
    stroke(86, 42, 42);
    //Draw lines between points along the circles to create eyes
    for(var i = 0; i < 360; i += 10){
        line( width * 0.2 + 20 * cos(radians(i)), 
              height * 0.4 - 20 * sin(radians(i)),
              width * 0.2 - 20 * cos(radians(i)),
              height * 0.4 - 20 * sin(radians(i)));
    }
    for(var i = 0; i < 360; i += 10){
        line( width * 0.5 + 20 * cos(radians(i)), 
              height * 0.4 - 20 * sin(radians(i)),
              width * 0.5 - 20 * cos(radians(i)),
              height * 0.4 - 20 * sin(radians(i)));
    }
    stroke(0);
    for(var i = 0; i < 360; i += 10){
        line( width * 0.2 + 5 * cos(radians(i)), 
              height * 0.4 - 5 * sin(radians(i)),
              width * 0.2 - 5 * cos(radians(i)),
              height * 0.4 - 5 * sin(radians(i)));
    }
    for(var i = 0; i < 360; i += 10){
        line( width * 0.5 + 5 * cos(radians(i)), 
              height * 0.4 - 5 * sin(radians(i)),
              width * 0.5 - 5 * cos(radians(i)),
              height * 0.4 - 5 * sin(radians(i)));
    }
    strokeWeight(2);
    stroke(214, 29, 29);
    //Draw the mouth by connectiing points on the ellipse
    for(var i = 0; i < 360; i += 10){
        line( width / 2.5 + 30 * cos(radians(i)), 
              height / 1.5 - 30 * sin(radians(i)),
              width / 3.5 - 30 * cos(radians(i)),
              height/ 1.5 - 30 * sin(radians(i)));
    }
}

For this project, I use the “for” loop to map out all the points on different lines and connect them together. When I drew the circles that are constructed by lines, I need to use cos and sine to calculate each point on the circle and then connect them together. The circles eventually form a face. Overall, I feel comfortable with the looping function.

Leave a Reply