Project 07- Curves

Graham Murtha

Section A

For this project, I wanted to make a series of layered petal-like formations with linework, all with different reactions to mouseX and mouseY. However, the cardioid caused some trouble, since despite how many times I manipulated the equation, it remained an very slow-growing shape on the left of the screen.

sketch
//Graham Murtha
//Section A
//Assignment 7
//gmurtha@andrew.cmu.edu


var vertices = 150; // number of vertices or coordinates

function setup() {
    createCanvas(480, 480);
    background(0);
    text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
    push();
    //moves origin to the center of the canvas
    translate(width/2,height/2);

    //draws loop for the three shapes

    background(120,0,60);// dark magenta-red
    Ranunculoid();
    Cardioid();
    Nephroid();
    pop();
}

function Ranunculoid(){
    //https://mathworld.wolfram.com/Ranunculoid.html
    
    //variables
    var x;
    var y;
    var a = mouseX/7
    var b = mouseY/100
    
    beginShape();
    noFill();
    stroke(255,180,255);  //light purple
    for(var i=0; i<vertices; i++){ // parametric equations
            var Ag = map(i,0,vertices,0,TWO_PI); // angle/theta
            x = a*((6*cos(Ag))-(b*cos(6*Ag)));
            y = a*((6*sin(Ag))-(b*sin(6*Ag)));
            vertex(x,y);
            
        endShape(CLOSE);
    }
}

function Cardioid(){ 
    //https://mathworld.wolfram.com/Cardioid.html
    
    //variables
    var x;
    var y;
    var a = mouseX/4
    var b = mouseY/30
    
    beginShape();
    noFill();
    stroke(255,150,0);//orange
    for(var i=0; i<vertices; i++){ // parametric equations
            var Ag = map(i,0,vertices,0,PI+QUARTER_PI); // angle/theta
            x = (a*cos(Ag)*(1-cos(Ag))*b);
            y = (a*sin(Ag)*(1-cos(Ag))*b);
            vertex(x,y);
            
        endShape(CLOSE);
    }
}

function Nephroid(){
    // https://mathworld.wolfram.com/Nephroid.html
    
    //variables
    var x;
    var y;
    var a = mouseX/6
    var b = mouseY/4
    
    beginShape();
    noFill();
    stroke(255); // white
    for(var i=0; i<vertices; i++){ // parametric equations
            var Ag = map(i,0,vertices,0,PI); // angle/theta
            x = a*(3*cos(Ag))-((cos(3*Ag))*b);
            y = a*(3*sin(Ag))-((sin(3*Ag))*b);
            vertex(x,y);
            
        endShape(CLOSE);
    }
}

Leave a Reply