Project 07 – Composition with Curves

Inspiration by Epicycloid Function

sketch
//Aarnav Patel
//aarnavp@andrew.cmu.edu
//Section D
//Project

var n = 1000;
var c;

function setup() {
    createCanvas(480, 480);
    c = color(random(255), random(255), random(255));

}

function draw() {
	background(0);
	for (var i = 0; i < 3; i++) {
		drawSpiral(i * width / 2);			//draws three times
	}

}

function mousePressed() {
	c = color(random(255), random(255), random(255));
}

function drawSpiral(w) {
	stroke(c);
	push();
	translate(w, height / 2);	//Setting the origin
	noFill();
	var x;
	var y;
    var a = constrain(mouseX, 0, width);		
    var b = constrain(mouseY, 0, height);		//Constrains aim to keep proportional when mouse is in Canvas

	
	strokeCap(ROUND);
    strokeJoin(ROUND);
    var t = 0;

    beginShape();					//Starting shape before vertices inputted
	for (var i = 0; i < n; i++) {							
		var t = map(i, 0, n, 0, TWO_PI);
		x = (a + b) * cos(t) - b * cos((a + b / b) * t);		//Using the elipcycloid function for the x and y (cos and sin)
		y = (a + b) * sin(t) - b * sin((a + b / b) * t);
		vertex(x, y);

	}
	endShape();					//ending the shape
	pop();						//resetting for the next time its called

}




/*

function drawSpiral() {
	//x	=	(a+b)cosphi-bcos((a+b)/bphi)

	//=	a^2[cos(2theta)+/-sqrt((b/a)^4-sin^2(2theta))].

	noStroke();
	var a = mouseX / 4;
	var b = 50;

	strokeCap(ROUND);
	strokeJoin(ROUND);
	var t = 0;
	push();
	translate(width / 2, height / 2);
	if (a > b) {
		//push();
		beginShape();
		for (var i = 0; i < n; i++) {
			t = map(i, 0, n, 0, TWO_PI);
			var r = sqrt(a * a * ( cos(t) + sqrt(pow((b / a), 4) - pow(sin(2 * t), 2))));

			var x = r * cos(t);
			var y = r * sin(t);
			console.log(x + ", " + y)

			vertex (-x, y);
		}
		endShape();
		//pop();
	}
		
	//push();
	beginShape();
	for (var i = 0; i < n; i++) {
		t = map(i, 0, n, 0, TWO_PI);
		var r = sqrt(a * a * ( cos(t) + sqrt(pow((b / a), 4) - pow(sin(2 * t), 2))));

		var x = r * cos(t);
		var y = r * sin(t);
		console.log(x + ", " + y)

		vertex(x, y);
	}
	endShape();
	pop();
}
*/

Leave a Reply