lee chu – project 07 – curves

lrchu

// lee chu
// section c
// lrchu@andrew.cmu.edu
// project - 07

// variables for equation
var angle;
var t;
var x;
var y;
var xx;
var yy;

// characteristics of shapes
var sizes = [];
var size;
var ct;
var step;

// color
var r;
var g;
var b;

function setup() {
    createCanvas(480, 300);
    noFill();
    strokeWeight(0);
    angle = 0;
    t = 20;

    // create sizing for layers
    for (h = 0; h < 60; h ++) {
        sizes.push(h * 3);
    }
    size = 20;
    ct = 200;

    // color control
    r = 36;
    g = 33;
    b = 40;
    step = 5;
}

function draw() {
    background(r, g, b);

    // change turn direction and rate
    if (mouseX < width / 2 & mouseX > 0 && mouseY < height && mouseY > 0) {
        angle -= (width / 2 - constrain(mouseX, 0, width / 2)) / width / 2 / 6;
    }
    if (mouseX > width / 2 & mouseX < width && mouseY < height && mouseY > 0) {
        angle += (constrain(mouseX, width/2, width) - width / 2) / width / 2 / 6;
    }

    // generate shapes
    for (j = 0; j < sizes.length; j ++) {
        cata(sizes[sizes.length - j]);
        r = (r + step * (j + 1)) % 255;
        g = (g + step * (j + 1)) % 255;
        b = (b + step * (j + 1)) % 255;
    }
    deltoid(sizes[1]);
}

function cata(size) {
    fill(r, g, b);
    push();
    translate(width / 2, height / 2);
    beginShape();
    for (i = 0; i < ct; i ++) {
        t = map(i, 0, ct, 0, 2 * PI);
        xx = 3 * cos(t) + cos(3 * t + 2 * angle) - cos(2 * angle);
        yy = - 3 * sin(t) + sin(3 * t + 2 * angle) - sin(2 * angle);
        vertex(xx * size, yy * size);
    }
    endShape();
    pop();
}

function deltoid(sizeD) {
    fill('black');
    push();
    translate(width / 2, height / 2);
    beginShape();
    for (i = 0; i < ct; i ++) {
        t = map(i, 0, ct, 0, 2 * PI);
        x = 2 * cos(t) + cos(2 * t);
        y = -2 * sin(t) + sin(2 * t);
        vertex(x * sizeD, y * sizeD);
    }
    endShape();
    pop();
}

I was intrigued by the deltoid catacaustic, which consists of the deltoid, a triangle bowing in, and the catacaustic which circumscribes the deltoid as it rotates around its axis. The center of all the layers of the catacaustic is the black deltoid in the middle of the canvas.

Paul Greenway – Project 07 – Curves

sketch

/*Paul Greenway
Section 1A
pgreenwa@andrew.cmu.edu
Project-07-Curves
*/

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

function draw() {
    background('black');
  
  
    //background spiral
  
    strokeWeight(50);
    
    size = 150;
    spiralWidth = 5;
    
    angleMap = map(mouseX, 0, width, 0, 20);
    angle = angleMap;
  
    Rcolor = map(mouseY, 0, height, 255,0);
    Gcolor = map(mouseY, 0, height, 100,150);
    Bcolor = map(mouseY, 0, height, 0,200);
  
    col = color(Rcolor,Gcolor,Bcolor, 50);

    stroke(col);
  
    drawSpiral();
  
  
  
    //foreground spiral
  
    strokeWeight(1);
    
    size = 150;
    spiralWidth = 5;
    
    angleMap = map(mouseX, 0, 300, 0, 20);
    angle = angleMap;
  
    Rcolor = map(mouseY, 0, height, 255,0);
    Gcolor = map(mouseY, 0, height, 100,150);
    Bcolor = map(mouseY, 0, height, 0,200);
  
    col = color(Rcolor,Gcolor,Bcolor);
    stroke('white');
    
    drawSpiral();
    
}
  
function drawSpiral() {
    oldX = width/2;
    oldY = height/2;
  
    for (let i=0; i<size; i++) {
        newAngle = (angle/10) * i;
        x = (width/2) + (spiralWidth * newAngle) * Math.sin(newAngle);
        y = (height/2) + (spiralWidth * newAngle) * Math.cos(newAngle);
      
        line(oldX, oldY, x, y);
        oldX = x;
        oldY = y;
  
    }
}

For this project I used an Archimedean spiral as the base curve type for my design. In order to make the movement of the spiral interactive I mapped the movement of the mouseX to the angle of the spiral and mouseY to the rgb value. This allowed for the properties of the spiral to be dynamic and based on the user’s mouse movement. In addition, I also added a larger opaque spiral to mirror the main one and act as a backdrop to the design.

Ian Kaneko Project-07-Curves

Honestly I had very little idea of what I was doing or where I was going with this project. In the end I just experimented around with different equations until I found something that looked cool. The background of my project is a failed attempt at adding more complex curve. However I kind of liked the randomness that it added so I decided to keep it around. I added a cruciform on top of it which ended up having a very interesting shaped fill space. To finish it off I added a “+” to the center that would rapidly spin, making it look circular.

ikaneko Curves



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

function draw() {
  background(0);

  squiggles();

  drawCruciform();

  drawSpinner();
  

}

// function for background squiggles
function squiggles() {
  strokeWeight(10);
  var x;
  var y;
  var a = width / 2;
  var nPoints = map(mouseY, 0, height, height / 4, height / 2); // It jiggles with y movement
  
  push()
  translate(width / 2, height / 2); // Puts the jumble in the middle of the canvas
  beginShape();
  for (i = 0; i < nPoints; i++) {
    stroke(250, i, 200);
    var t = map(i, 0, nPoints, 0, 2 * PI);  
    x = a * cos(t * (1 - 2 * pow(sin(t), 2))); // Attempted equations
    y = a * sin(t * (1 + 2 * pow(cos(t), 2))); // These didn't turn out how I expected but kinda liked them
    vertex(x, y);
    }
  endShape();
  pop();
 }

 // function for the cruciform
  function drawCruciform() {
    var x;
    var y;
    var a = map(mouseX, 0, width, width / 8, 200); // They move with the mouse
    var b = map(mouseY, 0, height, height / 8, 200);
    var nPoints = 300;
    strokeWeight(20);
    fill(150, 100, mouseX * mouseY / 300); // The interesting fill shape changes color

    translate(width / 2, height / 2); // Centers it around the middle of the canvas
    beginShape();
    
      for(z = 0; z < nPoints; z ++) {
        t = map(z, 0, nPoints, 0, 2 * PI);
        x = a * (1 / cos(t)); // Cruciform equations
        y = b * (1 / sin(t));
        
        vertex(x, y);

      }
    endShape();

    
  }

  function drawSpinner() { // Adds two rectangles to the cent that spin with mouse movement
    fill(200, 250, 200);
    push();
    rotate(mouseX * 10); // Spins very rapidly
    rectMode(CENTER);
    rect(0, 0, 50, 120); // These are already using the same translation as the cruciform
    rect(0, 0, 120, 50);
    pop();
  }

Chelsea Fan-Project 07-Curves

Curves

/* Chelsea Fan
Section 1B
chelseaf@andrew.cmu.edu
Project-07
*/

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

function draw() {
    background(mouseX/2, width/2, 255);
    drawHypocycloid1(); //draw hypocloid 1
    drawHypocycloid2(); //draw hypocycloid 2
}

function drawHypocycloid1() {
	//constrain mouse values to only affect when on canvas
	var x = constrain(mouseX, 0, width);
	var y = constrain(mouseY, 0, width); 
    noFill(); //no fill color
    strokeWeight(2); //line thickness
    stroke(width-mouseX); //stoke color changes based on mouseX

    //Hypocycloid 1
	push();
	translate(width/2, height/2); //begin at center of canvas
	var a = map(mouseX, 0, width, 0, 100);
	var b = map(mouseY, 0, height, 0, 100);
	beginShape();
	    for (var i = 0; i<=100; i++) {
    	    var t = map(i, 0, 100, 0, TWO_PI); //angle variable
    	    //hypocycloid1 equations
    	    x = (a+b)*cos(t) + b*cos((a+b)*t); 
    	    y = (a+b)*sin(t) - b*sin((a+b)*t);
    	    vertex(x, y);
    }
    endShape();
	pop()
}

function drawHypocycloid2() {
	//Hypocycloid 2
	push();
	translate(width/2, height/2); //begin at center of canvas
	var a = map(width-mouseX, 0, width, 0, 100);
	var b = map(width-mouseY, 0, height, 0, 100);
	beginShape();
	    for (var i = 0; i<=150; i++) {
    	    var t = map(i, 0, 100, 0, 360); //angle variable
    	    //hypocycloid2 equations
    	    x = (a+b)*cos(t) + b*cos((a+b)*t); 
    	    y = (a+b)*sin(t) - b*sin((a+b)*t);
    	    vertex(x, y);
    }
    endShape();
	pop()
}

Hypocycloid 1
Hypocycloid 2
Both Hypocycloids

It took me quite a while to figure out how to use an equation of a hypocycloid in javascript. In addition, I spent a lot of time looking through the MathWorld website looking at different curves and equations. I really enjoyed looking at the curves. I like the colors that I chose. The background is blue when the mouse is on the left and changes to pink as the mouse moves right. In addition, I like that the color of the hypocycloid drawings change from black to white and contrasts the background color. I am pretty happy with my product. However, I prefer being able to imagine (in my mind) what my code will create/draw. And, I can imagine what one individual hypocycloid looks like on the screen, but I could never imagine all the changes of my drawing based on where the mouse is.

Ammar Hassonjee – Project 07 – Curves

Interactive Curve Drawing

/* Ammar Hassonjee
    ahassonj@andrew.cmu.edu
    Section C
    Project 07
  */

  var nPoints = 100;
  var angle = 0;
  var angle2 = 0;
  var angle3 = 0;
  function setup() {
      createCanvas(480, 480);
  }


  function draw() {
      background(map(mouseY, 0, height, 0, 255), map(mouseY, 0, height, 0, 255), map(mouseY, 0, height, 80, 255));

      var a = map(mouseX, 0, width, 30, 300);
      var b = a * (3 / 8);
      var c = a / 8;
      // Drawing the deltoid curves
      fill(180, 0, 0);
      push();
      translate(width / 2, height / 2);
      rotate(radians(angle));
      drawDeltoidCurve(a);
      angle += map(mouseX, 0, 480, 2, 10);
      pop();

      // Varying the rotation angle
      fill(0);
      push();
      translate(width / 2, height / 2);
      rotate(radians(angle2 * -1));
      drawDeltoidCurve(b);
      angle2 += map(mouseX, 0, 480, 2, 10);
      pop();

      fill(180, 0, 0);
      push();
      translate(width / 2, height / 2);
      rotate(radians(angle));
      drawDeltoidCurve(c);
      angle += map(mouseX, 0, 480, 2, 10);
      pop();

      // Drawing the Ranunculoid curve with multiple iterations
      push();
      translate(width / 2, height / 2);
      rotate(radians(angle3));
      drawRanunculoidCurve(40);
      drawRanunculoidCurve(20);
      drawRanunculoidCurve(37);
      angle3 += map(mouseX, 0 , width, .1, 5);
      pop();


  }

  // Deltoid curve has parameter to alter size
  function drawDeltoidCurve(value) {
      // http://mathworld.wolfram.com/DeltoidRadialCurve.html
      var x;
      var y;

      noStroke();
      // Drawing the first deltoid
      beginShape();
      for (var i = 0; i < nPoints; i++) {
          var t = map(i, 0, nPoints, 0, TWO_PI);

          // curve equation
          x = (1 / 3) * value * (2 * cos(t) + cos(2 * t));
          y = (1 / 3) * value * (2 * sin(t) - sin(2 * t));
          vertex(x, y);
      }
      endShape(CLOSE);
  }

  // function has parameter to alter Ranunculoid curve size
  function drawRanunculoidCurve(size) {
      // http:mathworld.wolfram.com/Ranunculoid.html
      var x;
      var y;

      // Varying the strokeweight and color of the Ranunculoid curve
      stroke(map(mouseY, 0, height, 0, 255));
      strokeWeight(map(mouseX, 0, width, 10, 0.1));
      noFill();
      beginShape();
      for (var i = 0; i < nPoints; i++) {
          var j = map(i, 0, nPoints, 0, TWO_PI);

          // Curve equation
          x = size * (6 * cos(j) - cos(6 * j));
          y = size * (6 * sin(j) - sin(6 * j));
          vertex(x, y);
      }
      endShape(CLOSE);

    }

When I first started this assignment, I was a little overwhelmed by the requirements and confused about how to translate mathematical curves into a graphic. Once I found two curves however with simple mathematical formulas, the ranunculoid and deltoid, I was able to build functions and then vary their parameters using the mouseX and mouseY variables to make an interesting drawing!

Sean Meng – Project – 07 – Curves

hmeng-project 07

//Sean Meng
//hmeng@andrew.cmu.edu
//Section C
//Project-07-Curves

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

}

function draw() {
    background(0);

//Rotate the Epicycloid curve at canvas center point   
    push();    
    translate(width / 2, height / 2);
//Constrain and remap mouseX and mouseY value   
    var X = constrain(mouseX, 0, 480);
    var Y = constrain(mouseY, 0, 480);
    var c1 = map(mouseX, 0, 480, 0, 255);
    var c2 = map(mouseX, 0, 480, 0, 255);
//Define the radius of two circles that generate the Epicycloid curve
    var R = map(X, 0, width, 0, 200);
    var r = map(Y, 0, height, 0, 60);
//Change the stroke color as mouseX moves along the canvas 
    stroke(c1, 200, c2);
    noFill();
    beginShape();
    rotate(radians(X));
//Draw the first Epicycloid curve
    for(var angle = 0; angle < 360; angle += 2.5){
        CrvY = (R + r) * sin(angle) - r * sin((R + r) * angle / r);
        CrvX = (R + r) * cos(angle) - r * cos((R + r) * angle / r);
        curveVertex(CrvX, CrvY);
    }
    endShape();
    pop();


    push();
    
    translate(width / 2, height / 2);
    stroke(255);
//Constrain and remap mouseX and mouseY value 
    var X = constrain(mouseX, 0, 480);
    var Y = constrain(mouseY, 0, 480);
    var c3 = map(mouseX, 0, 480, 0, 255);
    var c4 = map(mouseX, 0, 480, 0, 255);
//Define the radius of two circles that generate the Epicycloid curve
    var R1 = map(X, 0, width, 0, 300);
    var r1 = map(Y, 0, height, 0, 60);
//Change the stroke color as mouseX moves along the canvas 
    stroke(c3, c4, 200);
    noFill();
    beginShape();
    rotate(radians(- X));
//Draw the second Epicycloid curve
    for(var angle = 0; angle < 360; angle += 4){
        CrvY1 = (R1 + r1) * sin(angle) - r1 * sin((R1 + r1) * angle / r1);
        CrvX1 = (R1 + r1) * cos(angle) - r1 * cos((R1 + r1) * angle / r1);
        curveVertex(CrvX1, CrvY1);
    }

    endShape();
    pop();    
}

In this project, I found it interesting to generate dynamic parametric drawing by understanding the mathematical equation of the epicycloid or hypercycloid, which is a plane curve produced by tracing the path of a chosen point on the circumference of a circle, which rolls without slipping around a fixed circle. Also, the variability of epicycloid itself is very flexible. By controlling variables such as the radius of the driving circle and the angle interval between each curve, the output image can be parametric and dynamic.

Epicycloid equation:

{\displaystyle x(\theta )=(R+r)\cos \theta \ -r\cos \left({\frac {R+r}{r}}\theta \right)}
{\displaystyle y(\theta )=(R+r)\sin \theta \ -r\sin \left({\frac {R+r}{r}}\theta \right),}
mouseX = 0 mouseY = 240
mouseX = 240 mouseY = 240
mouseX = 460 mouseY = 460

Ankitha Vasudev – Project 07 – Composition with Curves

sketch

//Ankitha Vasudev
//ankithav@andrew.cmu.edu
//Section B
//Project 07

//global variable
var nPoints = 600;

function setup() {
    createCanvas(450, 450); 
    frameRate(100);
}

function draw() { 
	background(0);

    //variables to change stroke color depending on mouse position
	var r = map(mouseX, 0, width, 50, 255);
	var g = map(mouseX, 0, width, 50, 255);
	var b = map(mouseY, 0, height, 50, 255);

    noFill();

    //calling Hypotrochoid function
	push();
    stroke(r, g, b);
    strokeWeight(0.15);
    translate(width/2, height/2);
	drawHypotrochoid();
	pop();

    //calling Astroid function
	push();
	stroke(g, b, r);
	strokeWeight(0.15);
	translate(width/2, height/2);
	drawAstroid();
	pop();

}

function drawHypotrochoid() {
    var x;
    var y;
    var h = width/2;
    //Mouse controls radius of hyportochoid
	var a = map(mouseX, 0, width, 0, width/100);
	var b = map(mouseY, 0, height, 0, height/200);
   
    beginShape();
      for (var i = 0; i < nPoints; i++) {
    	var angle = map(i, 0, 180, 0, 360);
    	//using formula for Hypotrochoid
    	//mathworld.wolfram.com/Hypotrochoid.html
    	x = (a - b) * cos(angle) + h * cos((a - b) * angle);
        y = (a - b) * sin(angle) - h * sin((a - b) * angle);
        vertex(x, y);
      }
    endShape();
 }

function drawAstroid() {
	var x;
	var y;
	//Mouse controls radius of Astroid
	var a = map(mouseX/2, 0, width, 0, width/5);
	var b = map(mouseY/2, 0, height, 0, height/10);

    beginShape();
      for (var i = 0; i < nPoints/2; i++) {
        var angle = map(i, 0, 100, 0, 360);
        //using formula for Astroid/Hypocycloid
        //mathworld.wolfram.com/Hypocycloid.html
        x = (a - b) * cos(angle) - b * cos(angle * (a - b));
        y = (a - b) * sin(angle) - b * sin(angle * (a - b));
        vertex(x, y);
      }
    endShape();
}

This project was the most difficult one so far because it took me a while to understand how to draw the curves the way I wanted them to be. I had to look at some online videos to get a better understanding. Additionally, reading the explanations behind the curve equations on Mathworld helped a lot. I played around with the variables and curve layers before finalizing on a Hypotrochoid and Astroid curve. However, the equation for an astroid was too complex so my curve uses a general Hypocycloid equation.

Both curves layered
Both curves layered

Julia Nishizaki – Project 07 – Curves

sketch

//Julia Nishizaki
//Section B
//jnishiza@andrew.cmu.edu
//Project 07 - Curves

var nPoints = 200;
var rotation = 0; //rotation for all Hypotrochoid Evolutes starts at 0

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

function draw() {
    background('white');
    stroke('white');
    
    //Hypotrochoid Evolutes:
    drawHypotrochoidEvolute(5, 300, 0.75, 2.5, color(139, 198, 63, 125)); //green
    drawHypotrochoidEvolute(10, 150, map(mouseX, 0, width, 0, 2), 1.5, color(173, 18, 26, 125)); //red
    drawHypotrochoidEvolute(5, 200, map(mouseY, 0, height, 0.25, 1), 2.5, color(177, 158, 219, 125)); //purple
    drawHypotrochoidEvolute(50, 150, map(mouseY, height, 0, 0, 2), 1.5, color(113, 198, 232, 125)); //blue
    drawHypotrochoidEvolute(25, 226, map(mouseX, width, 0, 0.25, 1.5), 2, color(253, 185, 63, 125)); //yellow
}

function drawHypotrochoidEvolute(pedalNum, angularity, size, strokeW, fillColor) { //pedalNum and angularity affect how many "pedals" you see, and their appearance
    // Hypotrochoid Evolute:
    // http://mathworld.wolfram.com/HypotrochoidEvolute.html
    push();
    translate(width / 2, height / 2);
    scale(size); //scales down Hypotrochoids (including stroke), specified under draw
    
    //causes all Hypotrochoid Evolutes to rotate at same rate, clockwise when mouse is below the middle of the canvas, counter-clockwise when above
    rotation += map(mouseY, 0, height, -TWO_PI / 800, TWO_PI / 800);
    rotate(rotation);
    
    //creates the Hypotrochoid Evolutes
    beginShape();
    fill(fillColor);
    strokeWeight(strokeW);
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        var h = map(mouseX, 0, width, -200, 200);
        //The equation for Hypotrochoid Evolutes
        x = (angularity - pedalNum) * cos(t) + h * cos((angularity - pedalNum) * (t / pedalNum));
        y = (angularity - pedalNum) * sin(t) - h * sin((angularity - pedalNum) * (t / pedalNum));
        vertex(x, y);
    }
    endShape();
    pop();
}

When approaching this project, I was a little overwhelmed, as I didn’t really know where to start, but after looking through the different roulette curves on the Mathworld curves website, I chose to focus on just the hypotrochoid evolute forms, as there were a large range of forms and examples for that particular curve that I could explore. After playing around with them a little, I started experimenting with colors and transparencies, and tried to go in the direction of a kaleidoscope, as I wanted my project to be constantly changing, and to reveal/conceal the different layers of colors depending on the location of your mouse.

Neutral State: When mouse is in center of canvas
Mouse near upper-right corner
Mouse near lower-left corner

Fanjie Jin – Project 07 – Curves

53

//Fanjie Jin
//Section C
//fjin@andrew.cmu.edu
//Project 7

function setup(){
    createCanvas(480, 480);
//set a initial start x and y value 
    mouseX = 100;
    mouseY = 100;
}

function draw(){
    background(100);
    push();
//tranlate geometry to the center of the canvas 
    translate(240, 240);
//constrain the mouse x value 
    var x = constrain(mouseX, 5, 480);
//constrain the mouse y value 
    var z0 = constrain(mouseY, 0, 240);
//constrain the mouse y value 
    var z1 = constrain(mouseY, 0, 240);
//constrain the mouse y value 
    var z2 = constrain(mouseY, 0, 360);

//remap the value of mouse X
    var a = map(x, 0, 480, 0, 200);
//remap the value of mouse X
    var b = map(x, 0, 480, 60, 60);
//remap the value of mouse X
    var c = map(x, 0, 480, 0, 100);

    noFill();
    beginShape();
//inside circle size variable 
//Hypotrochoid Variation 1
    for (var i = 0; i < 120; i++) {
//defining the positions of points
//parametric eq1
        x1 = (b - a) * sin(i) + z0 * sin((b - a) * i);
//parametric eq2
        y1 = (b - a) * cos(i) - z0 * cos((b - a) * i);
//color variation
        stroke(b * 2, a * 3, a + b);
        vertex(x1, y1);
    };
    endShape();
//Hypotrochoid Variation 2
    noFill();
    beginShape();
    for (var i = 0; i < 120; i++) {
//parametric eq3
        x2 = (b - a) * cos(i) + z1 * cos((c - a) * i);
//parametric eq4
        y2 = (b - a) * sin(i) - z1 * sin((c - a) * i);
        stroke(b , c, a + b);
        vertex(x2, y2);
    };
    endShape();
//Hypotrochoid Variation 3
    noFill();
    beginShape();
    for (var i = 0; i < 120; i++) {
//parametric eq5
        x3 = (b - a) * sin(i) + z2 * sin((a - c) * i);
//parametric eq6
        y3 = (b - a) * cos(i) - z2 * cos((a - c) * i);
        stroke(a , c, b);
        vertex(x3, y3);
    };
    endShape();
    pop();
}

In this project, I have tried to use the equation for Hypotrochoid to generate some mathematically interesting compositions. The equation express is above; however, I have simplified and add another parameter to the equation so that more parametric shapes would be generated. I really enjoyed this project as I think it is really great to learn how to actually use these mathematical to generate patterns and sometimes when you move the mouse a tiny bit, the entire composition will be drastically changed. In this project, there are three rings and each of them has a different equation and they would move simultaneously once the mouse position is changed.

x = 240 , y = 120
x = 200 , y = 160
x = 100 , y = 360

Mihika Bansal – Project – 07 – Curves

sketch

//Mihika Bansal 
//mbansal@andrew.cmu.edu 
//Section E 
//Project 5


function setup() {
    createCanvas(480, 480);
}
   
  
function draw() {
    
    var mx = constrain(mouseX, 0, 480); //constraining variables 
    var my = constrain(mouseY, 0, 480); 

    background(0, 0, 0, 75); 

    drawHypotrochoid(); //color one
    drawBlackHypotrochoid(); //black one 
    drawBlackHypotrochoid2(); //black one
    drawCenter(); //center flower ellipse 
    frameRate(500); 
     
}

function drawHypotrochoid(){

    push(); 
    translate(width / 2, height / 2); 
    var mx = constrain(mouseX, 0, 480); //constraining variables 
    var my = constrain(mouseY, 0, 480); 

    var rad1 = 230; //radius and parameters 
 
    var r = my * 0.4; //color variables
    var g = 100; 
    var b = mx * 0.4; 

    noFill();
    stroke(r, g, b); 
    strokeWeight(4); 

    var a1 = map(mx, 0, width, 0, 20);
    var b1 = map(my, 0, height, 0, 1); 

    beginShape(); 
    rotate(radians(angle));

    for(var i = 0; i < 360; i += 5){
        var angle = map(i, 0, 360, 0, 360); 

        var x = (a1 - b1) * cos(angle) + rad1 * cos((a1 - b1 * angle)); //equations of math functions
        var y = (a1 - b1) * sin(angle) - rad1 * sin((a1 - b1 * angle));

        curveVertex(x, y); //drawing points 

    }

    endShape(); 
    pop(); 

}

function drawBlackHypotrochoid(){

    push(); 
    translate(width / 2, height / 2); 
    var mx = constrain(mouseX, 0, 480); //constraining variables 
    var my = constrain(mouseY, 0, 480); 

    var rad1 = 380; //radius and parameters 
 

    noFill();
    stroke("black"); //overlapping the first function with a black one so that it cuts through it 
    strokeWeight(10); 

    var a1 = map(mx, 0, width, 0, 25);
    var b1 = map(my, 0, height, 0, 5); 

    beginShape(); 
    rotate(radians(angle));

    for(var i = 0; i < 360; i += 5){ //determines numnber of times loop runs 
        var angle = map(i, 0, 360, 0, 360); 

        var x = (a1 - b1) * cos(angle) + rad1 * cos((a1 - b1 * angle)); //equations of math functions
        var y = (a1 - b1) * sin(angle) - rad1 * sin((a1 - b1 * angle));

        curveVertex(x, y); //drawing points 

    }

    endShape(); 
    pop(); 

}
function drawBlackHypotrochoid2(){

    push(); 
    translate(width / 2, height / 2); 
    var mx = constrain(mouseX, 0, 480); //constraining variables 
    var my = constrain(mouseY, 0, 480); 

    var rad1 = 300; //radius and parameters 
 

    noFill();
    stroke("black"); //overlapping the first function with a black one so that it cuts through it 
    strokeWeight(10); 

    var a1 = map(my, 0, width, 0, 30);
    var b1 = map(mx, 0, height, 0, 2); 

    beginShape(); 
    rotate(radians(angle));

    for(var i = 0; i < 360; i += 5){ //determines numnber of times loop runs 
        var angle = map(i, 0, 360, 0, 360); 

        var x = (a1 - b1) * cos(angle) + rad1 * cos((a1 - b1 * angle)); //equations of math functions
        var y = (a1 - b1) * sin(angle) - rad1 * sin((a1 - b1 * angle));

        curveVertex(x, y); //drawing points 

    }

    endShape(); 
    pop(); 

}

function drawCenter(){
    translate(width / 2, height / 2);
    noFill();
    
    var mx = constrain(mouseX, 0, 480); // define constrain variables
    var my = constrain(mouseY, 0, 480);

    var angle = map(mx, 0, width, 0, 360);// define draw parameters
    var a2 = 70 + (.3 * mx);
    var b2 = 70 + (.3 * mx);

    var r = my * 0.5; //color variables
    var g = 50; 
    var b = mx * 0.5; 

    // define stroke
    strokeWeight(1);
    stroke(r, g, b);
    // define shape parameters
    beginShape();
    rotate(radians(angle));
    for (var t = 0; t < 160; t += 2.5){

        var x = a2 * (cos(t)); //equation function 
        var y = b2 * (sin(t));
        curveVertex(x,y);
        }
    endShape();
}

This project was quite confusing to grasp at first, but once I had an idea of what I wanted to do, I was able to explore the functions in an interesting manner. I spent a good amount of time playing around with my numbers in my code to get interesting interactions with the way that the curve moves, and forms. I was also able to layer curves in a way that created fun patterns. Here are some screen shots from the project at different states of the mouse location.