Project 07: Composition with Curves

sketch
var nPoints = 100;
var EPITROCHOID = 0; 
var CRANIOID = 1; 

var curveMode = EPITROCHOID;


function setup() {
    createCanvas(480, 480);
    frameRate(5);
}


function draw() {
    background(200,200,255);
    
    // curve
    push();
    translate(width / 2, height / 2);
    switch (curveMode) {
    case EPITROCHOID:
        drawEpitrochoidCurve();
        break;
    case CRANIOID:
        drawCranioidCurve();
        break;
    }
    pop();

    //moving shape
    let x = mouseX;
     let y = mouseY;
     let ix = width - mouseX;  // Inverse X
    let iy = height - mouseY; // Inverse Y
    ellipse(x, height/2, y, y);
     fill(255);
     noStroke();
    ellipse(ix, height/2, iy, iy);
}

function drawEpitrochoidCurve() {

    var x;
    var y;
    
    var a = mouseY;
    var b = mouseX;

    noStroke();
    fill(255,200,200);

    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        
        x = 4 * b * cos (t)* cos (t)* cos (t);
        y = a * sin (t) *sin (t)* sin (t);
        
      vertex(x, y);
    }
    endShape(CLOSE);
    
}

Leave a Reply