yoonyouk-project07-curves

sketch

//Yoon Young Kim
//Section E
//yoonyouk@andrew.cmu.edu
//Project07

var a = 50; //size of the rose curve
var nPoints = 100; //number of points on the curve

function setup(){
    createCanvas(480, 480);
    frameRate(10);
    noLoop();
}

function drawRoseCurve() {
    background(207, 212, 255); // blue background color

    stroke(145, 85, 112); //dark purple outline color
    strokeWeight(5);
    fill(204, 120, 157); //dusky pink fill color

    var t; //theta of the equation
    
    push();
    beginShape();

    translate(width/2, height/2);
    for(i = 0; i<mouseX; i++){ //number of points drawn based on the movement of mouseX
        var t = map(i, 0, mouseX + 40, 0, TWO_PI); //polar equation for the Rose Curve

      
        var r;
        var n = 4; // number of petals - when n is even, the function turns to 2n, therefore will create 8 petals

        r = a*cos(n*t); // drawing the Rose curve
        
        x = r *cos(t); //converting from polar to Cartesian
        y = r *sin(t); //converting from polar to Cartesian
        vertex(x, y);

    }
    endShape();
    pop();

}

function mouseMoved() {
    a = a + 1; //increasing the size of the flower when the mouse moves
    if(a>200){
        a=50;
    }
    drawRoseCurve();
}

I thought it was originally difficult to plug in the curve equations since we had to consider radians and Cartesian vs. polar equations. I wanted to do a rose curve because I was interested in how the lines would loop around in a flower like shape. In order to integrate the mouse movement with my curve I used the map function in order to determine the number of points of my curve. Therefore, as you move the mouse back and forth the loops will draw or undraw depending on the movement. Unfortunately, I was still unable to figure out how to make the entire curve close properly.

Leave a Reply