anabelle’s project 06

we always think too much about how time passes by too quickly. don’t be obsessed with aging, and just think about the good that comes with your birthday!

the background indicates to minute (to some extent). at the start of the hour, the background will be pink. it will become increasingly bluer the greater the minute is.

the number of strawberries on the cake indicate the hour of the day in a 12-hour cycle. to distinguish am and pm, the fruit will turn into blueberries in the am and strawberries in the pm.

the number of candles indicates the month and the number of gifts indicates the day.

sketch

// kayla anabelle lee (kaylalee)
// kaylalee@andrew.cmu.edu
// section c
// project 6

// define variables
let redValue, blueValue, greenValue;
let strawberryFill;
let giftCounter;
let giftDraw;

function setup() {
    createCanvas(480, 480);
    let h = hour(); 
    let m = minute();
    let d = day();
    let mon = month();

    // initialize background color
    redValue = 248;
    blueValue = 226;
    greenValue = 226;

    giftCounter = 0;

}

function draw() {
    // every minute, the background changes by this increment
    let redMinute = 1.25;
    let blueMinute = 0.633;
    let greenMinute = 0.1167;

    // final color will be (173, 188, 219)
    background(redValue - (redMinute*minute()), blueValue - (blueMinute*minute()), greenValue - (greenMinute*minute())); // final color will be (173, 188, 219)

    // set color variables for helper functions
    let cakeColor = color(255, 214, 148);
    let icingColor = color(246, 158, 178);
    let tableColor = color(112, 77, 36);

    let candleColor = color(247, 200, 238);
    let outerFire = color(245, 154, 142);
    let innerFire = color(255, 202, 150);

    let giftColor = color(171, 156, 217);
    let ribbonColor = color(248, 239, 233);

    // draw table and cake
    table(150, height - 105, 275, 190, tableColor); // 4/3 ratio
    cakeBase(150, height - 160, 150, 75, cakeColor);
    cakeBase(150, height - 230, 100, 50, cakeColor);

    // the number of candles = month (12 candles total)
    for (i = 1; i <= month()%12; i++) {
        if (i <= 6) {
            candle(i*15 + 96, 205, 8, 32, candleColor); // (top row)

        } else {
            candle(i*20 - 45, 255, 10, 40, candleColor); // 2/3 ratio (bottom row)
        }
    }

    // the number of gifts = day (31 total)
    giftDraw = true;
    giftCounter = 0;
    for (i = 0; i < 7; i++) {
        for (j = 0; j < 5; j++) {
            if (giftCounter >= day()) {
                giftDraw = false;
            } gift(280 + 30*i, 470 - 30*j, 25, 25, giftColor, ribbonColor, giftDraw);   
            giftCounter += 1;
        }
    }

    print (giftCounter);

    // now working on strawberries
    // for PM, fill is BLUE. for AM, fill is PINK)
    if (hour() <= 12) {
        strawberryFill = color(73, 104, 152);
    } if (hour() > 12) {
        strawberryFill = color(231, 84, 128);
    }

    // the number of strawberries = hour of the day (12 strawberries total)
    for (i = 1; i <= hour()%12; i ++) {
        if (i <= 6) {
            strawberry(i*16 + 92, 220, 15, 25, strawberryFill); // (top row)

        } else {
            strawberry(i*22 - 60, 270, 15, 25, strawberryFill); // 2/3 ratio (bottom row)
        }
    }

    textSize(20);
    textAlign(CENTER);
    text('life is too short to worry about time. eat some cake!', 220, 180, 300, 200);

}

/*my functions*/

function cakeBase(x, y, w, h, color) { // draws the bread part of cake
    var r = (w / 6);
    noStroke();
    fill(color);

    // base rectangle
    rectMode(CENTER);
    rect(x, y, w, h);

    // left arc
    arc(x - w/2 + r/2, y - h/2, r, r, radians(180), radians(270));

    // right arc
    arc(x + w/2 - r/2, y - h/2, r, r, radians(270), radians(360));

    // connect arcs
    line(x - w/2 + r/2, y - 2*r, x + w/2 - r/2, y - 2*r);
    rect(x, y - 7*r/4, w - r, r/2);

}

function table(x, y, w, h, color) { // draws table
    fill(color);
    rectMode(CENTER);
    noStroke();

    // vertical slabs
    rect(x - 3*w/10, y + 3*h/10, w/12, h/2); // left
    rect(x + 3*w/10, y + 3*h/10, w/12, h/2); // right

    // horizontal slabs
    rect(x, y, (3*w)/4, (h/6)); // bottom
    rect(x, y - h/12, w, h/12); // top
}

function gift(x, y, w, h, boxColor, ribbonColor, draw) { // draws one present

    if (!draw) {
        return false;
    }

    rectMode(CENTER);
    noStroke();

    fill(boxColor) // use arrays to create different colors for each gift

    // rectangles
    rect(x, y, 4*w/5, 4*h/5); // bottom
    rect(x, y - 2*h/5, w, h/10); // top

    // bow
    stroke(ribbonColor);
    strokeWeight(w/10);
    noFill();
    circle(x - w/8, y - h/2, w/4);
    circle(x + w/8, y - h/2, w/4);

    // box ribbon
    fill(ribbonColor);
    noStroke();
    rectMode(CENTER);
    rect(x, y, w/5, 8*h/10);
}

function candle(x, y, w, h, color) { // the width to height should be a 1/4 ratio
    rectMode(CENTER);
    fill(color);
    strokeWeight(1);
    stroke(150);
    rect(x, y, w, 4*h/5);

    fill(255, 0, 0, 150); // outer flame
    noStroke();
    ellipse(x, y - 3*h/5, 4*w/5, 3*h/10);

    fill(255, 165, 0, 150);
    ellipse(x, y - 11*h/20, 3*w/5, h/5);
}

function strawberry(x, y, w, h, color) { // draws one strawberry
    fill(color);
    noStroke();

    arc(x, y, w, h, radians(180), radians(0));
    arc(x, y, w, h/10, radians(0), radians(180));

}

function icing(x, y, w, h, color) {
    push();
    translate(x, y);
    fill(color); 
    stroke(color);

    x += cos(radians(x));
    y += sin(radians(y));

    point(x, y);
    pop();
}

Leave a Reply