Hyejo Seo – Project 07 – Curves

sketch

/*
Hyejo Seo
Section A
hyejos@andrew.cmu.edu
Project 7 - Curves 
*/
var nPoints = 200;
var angle = 0;

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

function draw() {
    background(56, 63, 81);
// placing Hypocycloid to be centered in the cavas 
    push();
    translate(width/2, height/2);
    drawHypocycloid();
    pop();
// Making two ranunculoids rotate depending on mouseX position 
    push();
    translate(width/2, height/2);
    rotate(radians(angle));
    angle += mouseX;
    drawRanunculoid();
    drawRanunculoid2();
    pop();
}

function drawHypocycloid(){
    var xh;
    var yh;
    var ah = map(mouseY, 0, 480, 150, 200); 
    var bh = 15;
    var hh = mouseX / 25;

    stroke(255, 200, 200);
    strokeWeight(5);
    noFill();
    beginShape();
// drawing hypocycloid 
    for (var i = 0; i < nPoints; i++) {
        var tH = map(i, 0, nPoints, 0, TWO_PI);     
        xh = (ah - bh) * cos(tH) + hh * cos((ah - bh) / bh * tH);
        yh = (ah - bh) * sin (tH) - hh * sin((ah - bh) / bh * tH);
        vertex(xh, yh);
    }
    endShape(CLOSE); 
}

function drawRanunculoid(){
    var ar = 20;
    stroke(255, 159, 28);
    strokeWeight(5);
    noFill();
    beginShape();
// drawing ranunculoid, for this one, I didn't need small increments with mapping 
    for (var i = 0; i < nPoints; i += 0.3){
      var xr = ar * (8 * cos (i) - cos (8 * i));
      var yr = ar * (8 * sin (i) - sin (8 * i));
      vertex(xr, yr);
}
endShape();
}

function drawRanunculoid2(){  
    var ar2 = 15;

    fill(215, 252, 212);
    noStroke();
    beginShape();
// drawing second ranunculoid 
    for (var i = 0; i < nPoints; i += 0.3){
      var xr2 = ar2 * (6 * cos (i) - cos (6 * i));
      var yr2 = ar2 * (6 * sin (i) - sin (6 * i));
      vertex(xr2, yr2);
}
endShape();
}


I spent fair amount of time browsing the Mathworld Curves website. How I approached this project was, instead of trying to plan the big picture (unlike the other projects), I chose one curve shape I liked and started there. Then, I slowly added other shapes. Unintentionally, my final work looks like a flower, which I am happy with. As the rotation gets faster and the hypercycloid expands, it almost looks like a blooming flower. Overall, it was interesting to play around with different  math equations. 

When mouseX is on the left edge of the canvas. Rotation is the slowest, and hypocycloid forms a circle.
When mouseX is on the far right of the canvas. Rotation is at its fastest and the hypocycloid forms curls.

Charmaine Qiu – Project – 07


sketch

In this project, it was fun to explore the different kinds of curves that can be created with math equations, and it intrigues me how interesting patterns can be generated through math. I took a pop art approach to my project by using bright colors and thick outlines.

The Hypotrochoid curve

The Astroid curve

//Charmaine Qiu
//charmaiq@andrew.cmu.edu
//section E
//Project - 07 - Composition Curve

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

function draw() {
    //set color to change with movement of mouse
    background(mouseX, mouseY, 100);
    drawHypotrochoid();
    drawAstroid();
}

function drawHypotrochoid() {
  //http://mathworld.wolfram.com/Hypotrochoid.html
  //constraining the mouse action to the canvas
  //map the variables in equation to a fit proportion of the curve
    var x = constrain(mouseX, 0, width);
    var y = constrain(mouseY, 0, height);
    var a = map(x, 0, width, 150, 200);
    var b = map(y, 0, height, 0, 50);
    var h = map(x, 0, width, 0, 50);

  //draw the first curve
    push();
    strokeWeight(10);
    beginShape();
    //rotate so that the beginning of curve does not show
    rotate(radians(120));
    //for loop that makes the shape
    for(var i = 0; i < 300; i += .045){
      var t = map(i, 0, 300, 0, TWO_PI);
      //equation of the curve
      x = (a - b) * cos(t) + h * cos(((a - b) / b) * t);
      y = (a - b) * sin(t) + h * sin(((a - b) / b) * t);
      vertex(x, y);
    }
    endShape(CLOSE);
    pop();

  //drawing the sencond curve
    push();
    //place it at the right bottom corner of canvas
    translate(width, height);
    strokeWeight(10);
    beginShape();
    //for loop that makes the shape
    for(var i = 0; i < 300; i += 0.045){
      var t = map(i, 0, 300, 0, TWO_PI);
      //equation of the curve
      x = (a - b) * cos(t) + h * cos(((a - b) / b) * t);
      y = (a - b) * sin(t) + h * sin(((a - b) / b) * t);
      vertex(x, y);
    }
    endShape(CLOSE);
    pop();
}


function drawAstroid(){
  //http://mathworld.wolfram.com/Astroid.html
    //draw first curve
    push();
    //place curve at center of canvas
    translate(width / 2, height / 2);
    strokeWeight(10);
    //constraining the mouse action to the canvas
    //map the variables in equation to a fit proportion of the curve
    var x = constrain(mouseX, 0, width);
    var y = constrain(mouseY, 0, height);
    var a = map(mouseX, 0, width, 150, 200);
    beginShape();
    //for loop that makes the shape
    for(var i = 0; i < 2 * PI; i += 0.045){
      //rotate with the increment of mouseX
      rotate(radians(x));
      //equation of the curve
      y = a * pow(sin(i), 3);
      x = a * pow(cos(i), 3);
      vertex(x, y);
    }
    endShape();
    pop();

    //draw first curve
    push();
    //place curve at center of canvas
    translate(width / 2, height / 2);
    strokeWeight(10);
    //constraining the mouse action to the canvas
    //map the variables in equation to a fit proportion of the curve
    var x = constrain(mouseX, 0, width);
    var y = constrain(mouseY, 0, height);
    var a = map(mouseX, 0, width, 20, 70);
    beginShape();
    //for loop that makes the shape
    for(var i = 0; i < 2 * PI; i += 0.045){
      //rotate with the increment of mouseY
      rotate(radians(y));
      //equation of the curve
      y = a * pow(sin(i), 3);
      x = a * pow(cos(i), 3);
      vertex(x, y);
    }
    endShape();
    pop();

}

Joanne Chui – Curves -Project 07

sketch

/*
Joanne Chui
Section C 
Project 6
*/

var nPoints = 200;

function setup(){
  createCanvas(400,400);
  frameRate(10);
}

function draw(){
  background(227, 127, 190);
  stroke(227, 175, 127);
  spirograph();
  push();
  translate(200, 200);
  for(var a = 0; a < 5; a++){
    rotate(a * PI/2);
    strokeWeight(3);
    spirograph();
  }
  pop();

}

function spirograph(){
  var x = constrain(mouseX, 0, width);
  var y = constrain(mouseY, 0, height);
  var r = 40;
  var s = 100; 

  push();
  translate(200, 200);
  beginShape();
  noFill();
  for(i = 0; i<nPoints; i++){
    var t = map(i, 0, nPoints, 0, 5*TWO_PI);
    x = (s - r)*cos(r*t/s) + i*(mouseX/100)*cos((1 - r/s)*t);
    y = (s - r)*sin(r*t/s) + i*(mouseX/100)*sin((1 - r/s)*t);
    vertex(x, y);
  }
  endShape(CLOSE);
  pop();
}

I made the original curve visible so that when a pattern is generated on the screen you can see where the pattern is derived from. I also liked the look of fewer lines so that the pattern seems more abstract.

Kristine Kim – Project 07 – Curves

sketch

//Kristine Kim
//Section D
//younsook@andrew.cmu.edu
//Project- 07- Curves
var nPoints = 70

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

function draw() {
    background(67, 42, 135);
    //calling all the functions 
    //drawing all of them on the center of the canvas

    push();
    translate(width/2, height/2);
    drawMovinglines();
    drawHypotrochoid();
    drawEpitrochoidCurve();   
    pop();
}

/*drawing the EpitrochoidCurve filled with
colors that are determined by mouseX and mouseY */
//the image that is drawing on top of everything
function drawEpitrochoidCurve(){

    var x;
    var y;

    var r1 = 100
    var r2 = r1 / mouseX;
    var h = constrain(mouseX, r1 , r2) 
    noStroke();
    fill(mouseY, 245, mouseX);
    beginShape();
    //for loop to draw the epitrochoidcurve
    for (var i = 0; i < nPoints; i++){
        var t = map(i, 0, nPoints, 0, TWO_PI);
        x = (r1 + r2) * cos(t) - h * cos(t * (r1 + r2) / r2);
        y = (r1 + r2) * sin(t) - h * sin(t * (r1 + r2) / r2);
        vertex (x,y);
    }
    endShape(CLOSE);
}
/*drawing the hypotrochoid with vertexs with
colors determined by mouseY */
//the first layer, drawing behind the epitrochoidcurve and movinglines

function drawHypotrochoid(){
    var x;
    var y;

    var r1 = 250
    var r2 = r1/ mouseX;
    var h = constrain(mouseY, r1, r2)
    stroke(mouseY, 200, 73);
    noFill();
    beginShape();
    //for loop for drawing the hypotrochoid form
    for (var i = 0; i < nPoints; i ++){
        var t = map(i, 0, nPoints, 0 , TWO_PI);
        x = (r1- r2) * cos(t) + h * cos(t * (r1 - r2) / r2);
        y = (r1- r2) * sin(t) + h * sin(t * (r1 - r2) / r2);
        vertex(x,y)
    }
    endShape(CLOSE);
}
/*drawing the constiently moving/wiggling circle
the radius and fill all controlled by mouseX and mouseY
the second layer, between the epitrochoidcurve and hypotrochoid */

function drawMovinglines(){
    var x;
    var y;
    var r1 = mouseX
    fill(mouseX, mouseY, mouseX)

    beginShape();
    //for loop for drawing the wiggling circle
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        var x = r1 * cos(t);
        var y = r1 * sin(t);
        vertex(x + random(-5, 5), y + random(-5, 5));
    }
    endShape(CLOSE);

}
    

I was first very intimidated by this project because it looked so complicated and intricate, but I studying the website provided to us was very helpful. The little explanations and gif helped me understand the concept a lot. There are just so many ways we can execute this project so I struggled with starting the project, but once I drew the Hypotrochoid function, I knew how to approach this project. I played around with the quantity of nPoints, fill(), stroke(), and a lot with mouseX and mouseY until I ended up with the product that I have right now . I enjoyed creating this a lot because I love discovering new images and findings so I was pleasantly surprised every single time I changed something in my code and found different drawings.

Lauren Park – Project – 07 – Curves

sketch

//Lauren Park
//ljpark@andrew.cmu.edu
//Section D
//Project-07-Curves

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

function draw() {
  background(10);
  
  drawHypotrochoid();
  drawHypocycloid();
}

function drawHypotrochoid() {
  var x;
  var y;
  
  //mouse controls color change for stroke
  var r = constrain(mouseX, 0, 300);
  var g = constrain(mouseY, 0, 300);
  var b = 150;
  
  push();
  fill('#53E9FF');
  stroke(r, g, b);
  strokeWeight(3);
  translate(width/2, height/2);
  
  //control hypotrochoid
  var ha1 = map(r, 0, width, 0, 100);
  var ha2 = map(g, 0, height, 0, 100);
  
  beginShape();
  for (var i = 0; i < 480; i+=3) {
    var angle1 = map(i, 0, 250, 0, 360);
  
  //equation of hypotrochoid from MathWorld curves site
  x = (ha1 - ha2)* cos(angle1) + b * cos((ha1 - ha2 * angle1));
  y = (ha1 - ha2)* sin(angle1) - b * sin((ha1 - ha2 * angle1));
  vertex(x, y);
  }
  endShape();
  pop();
}

function drawHypocycloid() {
  var x;
  var y;
  
  //mouse controls color change for stroke
  var r = map(mouseX, 0, width, 50, 255);
  var g = map(mouseY, 0, height, 50, 255);
  
  push();
  fill(254, 193, 255, 140);
  stroke(r, g, 255);
  strokeWeight(0.3);
  translate(width/2, height/2);
  
  //control hypocycloid
  var hy1 = map(mouseX, 0, width, 0, 300);
  var hy2 = map(mouseY, 0, height, 0, 300);
  
  beginShape();
  for (var a = 0; a < 200; a+=3) {
    var angle2 = map(a, 0, 100, 0, 360);
    
    //equation of hypocycloid from MathWorld curves site
    x = (hy1 + hy2)* cos(angle2) + hy2* cos((hy1 + hy2)*angle2);
    y = (hy1 + hy2)* sin(angle2) - hy2* sin((hy1 + hy2)*angle2);
    vertex(x, y);
  }
  endShape();
  pop();
}

My idea for this project initially came from visuals of a rotating flower. However, throughout this process of figuring out this project, I became more interested in intricate patterns within this flower shape. And so, I was more focused on adding different color changes and perspectives when the mouse moves, to show off different designs of this form. When the mouse is somewhere near the top left edge of the canvas, I want to show the two different curves separately to represent seed-like forms, so that when the mouse moves in other directions, then the flower can gradually grow and spread to a wider view. Overall, it was very challenging but very satisfying to create patterns that remind of the kaleidoscope effect.

Gretchen Kupferschmid-Project 07- Curves

sketch

//Gretchen Kupferschmid
//Section E
//gkupfers@andrew.cmu.edu
//Project-07-Curves

function setup() {
    createCanvas(480,480);
}
 function draw (){
    //gradient picking color
    var gradient1 = color(255, 238, 87); 
    var gradient2 = color(247, 119, 179); 
    createGradient(gradient1, gradient2);
    
    push();
    //moves all objects to center of canvas
    translate(width/2, height/2);
    //rotates shapes with movement of mouse X value from values 0 to pi
    rotate (map(mouseX, 0, width, 0, 10));
    circlePedal();
    deltoidCata();
    hypotrochoid();
    pop();
 }

function deltoidCata(){
    //mapping colors to mouse
    colorR = map(mouseX, 0, width, 200, 255);
    colorB = map(mouseY, 0, height, 200, 255);
    
    //mapping factor of deltoid to mouse
    g = map(mouseX, 0, width, 0, 100);
    g = map(mouseY, 0, height, 25, 50);
    
    //stroke & fill
    strokeWeight(5);
    fill(colorR, 250, colorB);
    stroke(0);
    

    // creating deltoid catacaustic
    beginShape();
    for (var i = 0; i < 200; i ++) {
        
        var angle = map(i, 0, 200, 0, 2*(TWO_PI));
        //formula for deltoid catacaustic
        x= ((2 *(cos(angle))) + (cos(2*angle)))*g ;
        y= ((2 *(sin(angle))) - (sin(2*angle)))*g ;
        vertex(x,y);
    }
    endShape();
}

function circlePedal(){
    //mapping colors to mouse X & Y
    colorR = map(mouseX, 0, width, 80, 200);
    colorG = map(mouseX, 0, width, 0, 50);
    colorB = map(mouseY, 0, height, 70, 170);
    
    //mapping factor multiplied by to mouse X & Y
    t = map(mouseX, 0, width, 150, 250);
    t = map(mouseY, 0, height, 130, 200);
    
    //stroke & fill
    strokeWeight(2);
    fill(colorR, colorG, colorB);
    stroke(255);
    
    //creating circle pedal
    for (var i = 0; i < 500; i ++) {
        
        var angle = map(i, 0, 500, 0, 2*(TWO_PI));
        //formula for circle pedal
        var x1 = cos(angle);
        var y1 = sin(angle);
        var x2 = t *((cos(angle)) -( y1 * cos(angle) * sin(angle)) + (x1 * pow(sin(angle),2))); 
        var y2 = (.5* (y1 + (y1 * cos(2*angle))+ (2*sin(angle))- (x1 * sin(2*angle)))) * t;
        vertex(x2,y2);
    }
    endShape();
     
}

function hypotrochoid(){
    //mapping size of hypotrochoid to mouse
    a = map(mouseX, 0, width, 200, 350);
    b = map(mouseY, 0, height, 100, 200);
    h = map(mouseY, 0, height, 2, 105);
    
    //stroke & fill
    strokeWeight(2);
    noFill();
    stroke(255);

    // creating hypotrochoid
    beginShape();
    for (var i = 0; i < 500; i ++) {
        // hypotrochoid formula
        angle = map(i, 0, 500, 0, TWO_PI);
        var x = (a - b) * cos(angle) + h * cos((a - b) / b * i);
        var y = (a - b) * sin(angle) + h * sin((a - b) / b * i);
        vertex(x, y);
    }
    endShape();
}

//function gradient 
function createGradient(top, bottom) {
    for(var i = 0; i <= height; i++) {
      var mapColor = map(i, 0, height, 0, 1);
      var interA = lerpColor(top, bottom, mapColor);
      stroke(interA);
      line(0, i, width, i);
    }
}

I started the project with just creating the deltoid curve and the circle pedal curve, but realized that just them two together weren’t creating a very interesting composition even though the formulas to create them were pretty complex. Even with altering numbers, mapping values, and angle amounts, I still wasn’t getting anything particularly interesting or complex looking. So, I decided to add a more circular and dynamic curve of the hypotrochoid, which can be altered by various radii values and its repeating structure.

Joseph Zhang – Project 07 – E

For this project, I wanted to play with hypotrochoid forms and astroids in hopes of making something pretty dynamic. I had really brief understanding of roulettes from high school mathematics so a lot of my learning came from going through the Wolfram Alpha website and learning about each form. At the end, these were the two that I wanted to continue playing with.

Quiet honestly, I had no idea how it would come out at the end and much of the process just came from experimenting with mouse positions, mapping, and tweaking with equations. Below are some screenshots of its different forms.

sketch

// Joseph Zhang
// Section E
// haozhez@andrew.cmu.edu
// Project-07: Composition with Curves

var points = 2000;
var rotateCount = 0;

function setup() {
    createCanvas(480, 480);

}

// calls each shape and continuously rotates the form
function draw() {
    background(20);
    push();
        translate(width / 2, height / 2);
        rotate(rotateCount);
        rotateCount++;
        drawAstroid();
        drawHypo();
    pop();
}

// draws the Astroid form (inside shape)
function drawAstroid() {
    // colors is dependent on mouse position
    colorR = map(mouseY, 0, width, 0, 255);
    colorG = map(mouseX , 0, width, 0, 255);
    colorB = map(mouseX , 0, width, 0, 255);
    stroke(colorR , colorG, colorB);
    noFill();
    strokeWeight(1);

    // for loop to draw astorid form
    beginShape();
    petal = int(map(mouseX, 0, width, 4, 10));
    size = int(map(mouseX, 0, width, 0, 100));
    for (var i = 0; i < points; i++){
        t = map(i, 0, points, 0, TWO_PI);
        x = (size / petal) * ((petal - 1) * cos(t) + cos((petal - 1) * t));
        y = (size / petal) * ((petal - 1) * sin(t) - sin((petal - 1) * t));
        vertex(x,y);
    }
    endShape();
}

// draws the hypotrochoid form (outside shape)
function drawHypo() {
    // colors is dependent on mouse position
    colorR = map(mouseX, 0, width, 0, 255);
    colorG = map(mouseY , 0, width, 0, 255);
    colorB = map(mouseY , 0, width, 0, 255);
    stroke(colorR , colorG, colorB);
    strokeWeight(1);
    
    //for loop to draw astroid form
    a =  map(mouseX, 0 , width, 200, 350);
    b =  map(mouseY, 0 , width, 100, 200); 
    h =  map(mouseY, 0 , width, 2, 105); 
    
    beginShape();
    for (var i = 0; i < 10000; i++){

        t = map(i, 0, 500, 0, TWO_PI);
        x = (a - b) * cos(t) + h * cos((a - b) * (t / b));
        y = (a - b) * sin(t) - h * sin((a - b) * (t / b));
        vertex(x, y);
    }
    endShape();
}

Form 1
Form 2
Form 3
Form 4

Monica Chang- Project-07-Curves

sketch

//Monica Chang
//mjchang@andrew.cmu.edu
//Section D
//Project-07-Curves

var nPoints = 100;
var radiusX;
var radiusY;
var separation = 125;

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

function draw() {
    background("darkcyan");
    fill(255, 255, 255, 64);
    
    radiusX = mouseX;
    radiusY = mouseY;

    drawCircles();
    drawEpitrochoidCurve();
    drawDeltoid();
}

//circle elements

function drawCircles() {
  
  // a sequence of little, circle elements
    push();
    translate(width / 2, height / 2);
    for (var i = 0; i < nPoints + 10; i++) {
        var theta = map(i, 0, nPoints, 0, TWO_PI);
        var px = radiusX / 2 * cos(theta);
        var py = radiusY / 2 * sin(theta);
      
        stroke("lightcyan");
        strokeWeight(1);
        circle(px - 5, py - 5, 8, 8);
    }
    pop();
  
}


function drawDeltoid() {
    //Deltoid:
    //http://mathworld.wolfram.com/Deltoid.html
    beginShape();
    nPoints = 40;
    for (var i = 0; i < nPoints; i++) {   
    	var angle = map(i, 0, 180, 0, 360);
        var radius = 70;
        var a = map(mouseX, 0, height, 5, 80)
        var b = map(mouseY, 0, height, 5, 90)
        
        //x-coordinate for deltoid
        var x = (a - b) * cos(angle) + radius * cos((a - b * angle));
        //y-coordinate for deltoid
        var y = (a - b) * sin(angle) - radius * sin((a - b * angle));
        rotate(radians(angle));
        noFill();
        strokeWeight(3);
        stroke("red");
        vertex(x, y);
      }
    endShape();
    

}

function drawEpitrochoidCurve() {
    // Epicycloid:
    // http://mathworld.wolfram.com/Epicycloid.html
    
    var x2;
    var y2;
    
    var a = 80.0;
    var b = a / 2.0;
    var h = constrain(mouseY / 8.0, 0, b);
    var ph = mouseX / 30.0;
    
    noFill();
    stroke("tan");
    strokeWeight(1);
    beginShape();
    translate(width / 2, height / 2);
    for (var i = 0; i < nPoints + 10; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        
        x2 = (a + b) * cos(t) - h * cos(ph + t * (a + b) / b);
        y2 = (a + b) * sin(t) - h * sin(ph + t * (a + b) / b);
      
        //switching x and y-coordinates to create a band of waves/
        vertex(x2, y2);
        vertex(y2, x2);
    }
    endShape(CLOSE);
    
}

Bottom Left
Bottom Right
Top Left
Top Right

This project definitely had me studying the formulas 75% of the time for me to really start putting anything together. However, once I got the gist of the formulas, it was really entertaining for me. I began with studying the deltoid curve and I realized this particular curve created so many different shapes. Thus, I wanted to provide a more constant curve which became the sequence of circles which are relatively more static to create a sense of balance.

Kimberlyn Cho- Project 07- Curves

ycho2-07

/* Kimberlyn Cho
Section C
ycho2@andrew.cmu.edu
Project-07 */

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

function draw() {
	push();
	background(0);
	strokeWeight(2);
	noFill();
	translate(width / 2, height / 2);
	stroke(188, 19, 254);
	drawHypotrochoidCurve();
	stroke(250, 237, 39)
	drawEpitrochoidCurve();
	pop();
};

//Hypotrochoid Curve
function drawHypotrochoidCurve() {
	//http://mathworld.wolfram.com/Hypotrochoid.html

	//equations
	var x;
	var y;

	//parameters to control curve
	var a = map(mouseX, 0, width, 0, 200)
	var b = a / 20
	//curve radius
	var h = map(mouseY, 0, height, 0, 200)

	//drawing curve
	push();
	beginShape();
	for (var i = 0; i < 100; i ++) {
		var t = map(i, 0, 100, 0, TWO_PI)
		x = (a - b) * cos(t) + h * cos(((a - b) / b) * t)
		y = (a - b) * sin(t) - h * sin(((a - b) / b) * t)
		vertex(x, y)
	};
	endShape();
	pop();
} 

//Epitrochoid Curve
function drawEpitrochoidCurve() {
	//http://mathworld.wolfram.com/Epitrochoid.html

	//equations
	var x;
	var y;

	//parameters to control curve
	var a = map(mouseX, 0, width, 0, 250)
	var b = a / 20
	//curve radius
	var h = map(mouseY, 0, height, 0, 250)

	//drawing curve
	push();
	beginShape();
	for (var i = 0; i < 100; i ++) {
		var t = map(i, 0, 100, 0, TWO_PI)
		x = (a + b) * cos(t) - h * cos(((a + b) / b) * t)
		y = (a + b) * sin(t) - h * sin(((a + b) / b) * t)
		vertex(x, y)
	};
	endShape();
	pop();
} 

I found the flexibility of this project to be fun in the multitude of possible outcomes it allowed for even with the same kind of curves. The initial exploration of the various equations and curves was interesting– especially in discovering cool, interesting shapes or curves with just math equations. Although the complex equations were intimidating in my first approach to the project, it was pretty amusing to see how the curves reacted to changes in the different parameters. I chose to layer two different types of curves to create an illusion of depth and overlap. Overall, I enjoyed this project and think it was a great introduction to a mathematical approach to design through p5js.

state 1
state 2

Alec Albright – Project 07 – Curves

sketch

// Alec Albright
// aalbrigh@andrew.cmu.edu
// Section B
// Project 07

var nPoints = 100; // number of points used to draw curves

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

function draw(){
    background("lightpink");

    // center the shapes
    push();
    translate(width / 2, height / 2);

    // draw all the shapes
    drawHippopede();
    drawEpicycloid();
    drawHypotrochoid();

    pop();
}

// draws Hippopede
function drawHippopede() {
    var x; // x coordinate of vertex
    var y; // y coordinate of vertex
    var r; // polar coordinate
    var a = mouseX / 2 // main parameter of the curve
    var b = map(a, 0, 480, 100, 240); // circle radius
    var rotation = map(mouseY, 0, 480, 0, TWO_PI); // amount of rotation

    // thickness of line proportional to the circle radius
    strokeWeight(b / 5);
    stroke("white");
    noFill();

    // rotate shape
    push();
    rotate(rotation);

    // start drawing the shape, one point at a time
    beginShape();
    for(var i = 0; i < nPoints; i++){
        var t = map(i, 0, nPoints, 0, TWO_PI);
        
        // find r (polar equation)
        r = sqrt(4 * b * (a - b * sinSq(t)));

        // convert to x and y coordinates
        x = r * cos(t);
        y = r * sin(t);

        // draw a point at x, y
        vertex(x, y);
    }
    endShape();
    pop();
}

// draws hypotrochoid
function drawHypotrochoid() {
    var x; // x coordinate of vertex
    var y; // y coordinate of vertex
    var a = map(mouseX, 0, 480, 50, 150); // radius of the interior circle
    var b = 3; // radius of the petals
    var h = mouseX / 10; // distance from center of interior circle
    var red = map((mouseX + mouseY) / 2, 0, 480, 0, 255); // how much red
    var blue = map(mouseY, 0, 480, 0, 255); // how much blue
    var alpha = map(mouseX, 0, 480, 50, 255); // how opaque
    var rotation = map(mouseY, 100, 300, 0, TWO_PI); // amount of rotation

    strokeWeight(2)
    stroke("white");

    // control color and opacity with mouse location
    fill(red, 0, blue, alpha);

    // control rotation with mouseY
    push();
    rotate(rotation);

    // create the shape itself
    beginShape();
    for(var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);

        // use parametric euqations for hypotrochoid to find x and y
        x = (a - b) * cos(t) + h * cos((a - b) / b * t);
        y = (a - b) * sin(t) - h * sin((a - b) / b * t);

        // draw a point at x, y
        vertex(x, y)
    }
    endShape(CLOSE);
    pop();
}

// draws an epicycloid
function drawEpicycloid() {
    var x; // x coordinate of vertex
    var y; // y coordinate of vertex
    var a = map(mouseX, 0, 480, 50, 200); // radius of interior circle
    var b = map(mouseY, 0, 480, 10, 50); // radius of petals
    var blue = map((mouseX + mouseY) / 2, 0, 480, 0, 255); // how much blue
    var red = map(mouseY, 0, 480, 0, 255); // how much red
    var rotation = map(mouseY, 100, 300, 0, TWO_PI); // how muhc rotation

    // control color with mouse location
    strokeWeight(10)
    stroke(red, 0, blue);

    // control rotation with mouse location
    push();
    rotate(rotation);

    // start drawing shape
    beginShape();
    for(var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);

        // find coordinates using epicycloid parametric equations
        x = (a + b) * cos(t) - b * cos((a + b) / b * t);
        y = (a + b) * sin(t) - b * sin((a + b) / b * t);

        // draw a point at x, y
        vertex(x, y);
    }
    endShape();
    pop();
}

// defines sin^2 using trigonometric identities
function sinSq(x) {
    return((1 - cos(2 * x)) / 2);
}

In order to put together this project, I started with a simple curve, the hippopede, and began to implement increasingly more complex ones. Once I was able to draw the three curves (hippopede, hypotrochoid, and epicycloid), I started mapping various features of the curves to things like color, transparency, stroke weight, and rotation until I was satisfied with the results. Particularly, the color mapping was interesting to me because I utilized the average of the mouseX and mouseY coordinates in order to determine some aspects of color like the amount of red in the hypotrochoid and the amount of blue in the epicycloid. This allowed me to have more freedom to speculate interesting relationships that could be created using the coordinate system.

mouseX = 400, mouseY = 50
mouseX = 240, mouseY = 400
mouseX = 50, mouseY = 200
mouseX = 480, mouseY = 240