Project 07

logarithmic spirals!

sketch
// Sowang Kundeling skundeli Section C Project 07

var theta; // angle from x-axis
var r; // dist from the origin
var nPoints = 700;

function setup() {
    createCanvas(480, 480);
    angleMode(DEGREES);
}

function draw() {
    background(28+mouseY, 74, 55+mouseX); // green

    strokeWeight(2);
    startAngle = constrain(mouseY, 100, 100);
  
    // spirals
    stroke(110, 53, 140); // dark purple
    logSpiral(mouseY, startAngle);
    stroke(199, 129, 227) // light purple
    logSpiral(mouseY, startAngle+20);
    stroke(76, 63, 152) // dark blue
    logSpiral(mouseX+25, startAngle+40);
    stroke(136, 128, 224) // light blue
    logSpiral(mouseX+50, startAngle+60);
    stroke(176, 69, 149) // pink
    logSpiral(mouseX+75, startAngle+85);
    stroke(224, 110, 196) // pink
    logSpiral(mouseX, startAngle+95);

}

function logSpiral(r, theta, color) { // logarithmic spiral
    noFill(); // use noFill or else only one line is shown
    var a; // arbitrary constant
    var b; // arbitrary constant
    
    beginShape();
    for (i=0; i < nPoints; i++) { // apply nPoints onto spirals
        a = (width/2) + (r+i) * cos(theta+3*i);
        b = (height/2) + (r+i) * sin(theta+3*i);
        vertex(a, b);
    }
    endShape();
}

Leave a Reply