akluk-Project-07-curves

sketch

//Alvin Luk
//Section A
//akluk@andrew.cmu.edu
//Project-07


var nPoints = 200;
var edges = 2;


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


function draw() {
    background(255);
    // draw the frame
    fill(0); 
    noStroke();
    stroke(0);
    noFill(); 
    rect(0, 0, width-1, height-1); 
    
    // draw the curve
    push();
    translate(width / 2, height / 2);
    drawCurve(edges);
    pop();
}

//--------------------------------------------------
function drawCurve() {
    // Hypotrochoid
    // http://mathworld.wolfram.com/Hypotrochoid.html
    // draws multiple hypotrochoid with differeing h's
    for (var j = 0; j < 30; j++){
    var x;
    var y;
    
    var a = map(mouseX,0,width,0,200);
    var b = a/edges;
    var h = map(mouseY,0,height,0,4*j);
    //changes color gradient depending on which hypotrochoid currently at
    //and also the position of mouseX and mouseY
    var red = map(j,0,30,0,255);
    var green = map(mouseX,0,width,0,255);
    var blue = map(mouseY,0,height,0,255);
    stroke(color(red,green,blue));

    //draws single hypotrochoid
 	noFill();
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        
        x = (a - b) * cos(t) + h* cos(t * (a - b) / b);
        y = (a - b) * sin(t) - h * sin(t * (a - b) / b);
        vertex(x, y);
    }
    endShape(CLOSE);
	}	


}

//adds number of edges/ corners each time the mouse is pressed
function mousePressed() {
    edges +=1
    if (edges > 7){
    	edges = 2;
    }
}
//--------------------------------------------------

For this project. I first followed the guidelines provided in the assignments and chose a graph from the mathworks curves section. I chose the Hypotrochoid, since there was a lot of variables in the parametric equations of the curves that I could play with that enabled me to create varying versions and variations of the curve. I also thought that just one hypotrochoid seems kind of static. So I decided to use a for loop to generate numerous hypotrochoid super imposed on each other with a changed parameters. I also made it so the color changes based on the position of x and y. Clicking also changes the ratio of a and b creating new different classes of hypotrochoid. Below are some screenshots of what my program creates.

sntong-Project-07-Composition-with-Curves

sketch

//scarlet tong
//sntong@andrew.cmu.edu
// Section A
// Project 07 - Composition with Curves


//intitalize a value before using it for the x and y equations
var a = 0;

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

function draw(){
  //changing the alpha channel allows the movements of the dots to "lag" behind
  //creating interesting "tails" for each dot
  background(250,170,23,100);
  push();
  translate(150, height/2); // so that we can see the curve on the cancaus
  beginShape();
  for(var i = 0; i < 200; i++){
    var theta = map(i,0,100,0,360);
    // a controls how much the curve "bends" and loops
    var a = map(mouseX, 0,480,-7,7);
    //Conchoid of de Sluze equation from Wolfram MathWorld
    var x = (1/cos(theta)+(a*cos(theta)))*cos(theta);
    var y = (1/cos(theta)+(a*cos(theta)))*sin(theta);
    // color of the dots changes according to mouse position
    var col = map(mouseY, 0,300,0,255);
    var jitter = map(mouseY, 0,300,0,7);
    noStroke();
    fill(col);
    //"polar array" the Conchoid from the center
    rotate(90);
    //the first dotted line
    ellipse(x*20+random(0,1),y*20+random(0,1),2,2);
    //the second dots are rotated on a different angle of offset
    rotate(45);
    //the second dotted line
    fill(255-col);
    ellipse(-x*10+random(0,1),-y*10+random(0,1),2,2);
    // another layer of dots with larger diameters are then introduced to highlight
    //specific paths the curve took.
    if(i%4==0){
      ellipse(x*20+random(0,1),y*20+random(0,1),3,3)
    }
  }
  endShape(CLOSE);
  pop();

}

For this project I choose the to use the Conchoid of de Sluze equation found on Wolfram MathWorld as my base curve. I did more experimenting while I was coding and layer more alterations to the curve configuration each step. In this assignment I wanted to explore the use of density so that it implies a set of lines; however once the image is static it becomes harder to tell which dots make up a specific curve. I started off with a set of mirrored curves where one is scaled to a factor to another. Then I added motion of the curves by tracking mouseX and mouseY. From there color change is referred to mouse position and rotation is introduced to the curves.

thlai-Project-07-Curves

My math is a bit rusty so my head spun when perusing the Mathworld website. I first played around with the equations given in the project example, which resulted in this:

I studied each part of the code until I was able to create another curve. I created a Cartioid Curve that increases size and rotates based on mouseX, and the background also changes based on the mouseX and mouseY positions.

sketch

// Tiffany Lai
// 15-104, Section A
// thlai@andrew.cmu.edu
// Project 07 - Curves

var nPoints = 500; // amount of points in curve

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

function draw() {
    // background changes colors based on mouse position
    var r = map(mouseX, 0, width, 50, 200);
    var g = map(mouseY, 0, width, 150, 200);
    var b = map(mouseX, 0, height, 200, 255);
    background(r - 100, g - 100, b - 100, 130);

    drawCurve(); // draw the cardioid curve
}

function drawCurve(){
    //mathworld.wolfram.com/Cardioid.html

    var x; // defining x and y positions of vertices in curve
    var y;

    var a = map(mouseX, 0, width, 0, 100); // map mouseX from 0 to 5

    fill(100, 200, 255, 20); // blue
    stroke(255); // white
    translate(width/2, height/2);

    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        x = a * (1 + cos(t)) * cos(t); // parametric equation of cardioid
        y = a * (1 + cos(t)) * sin(t); // parametric equation of cardioid

        rotate(radians(mouseX/500)); // rotate based on mouseX
        ellipse(x, y, 1, 1); // draw spiral of dots
        vertex(x, y); // draw the first curve (blue)
    }
    endShape();

    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        x2 = a * (1 + cos(t)) * cos(t); // parametric equation of cardioid
        y2 = a * (1 + cos(t)) * sin(t); // parametric equation of cardioid

        rotate(radians(mouseX/500)); // rotate based on mouseX
        fill(255, 150, 150, 20); // pink
        vertex(x2, y2); // draw the second curve (pink)
    }
    endShape();
}

jennyzha – project 07

sketch

// Jenny Zhang
// Section D
// jennyzha@andrew.cmu.edu
// Project 07 

//http://mathworld.wolfram.com/Epitrochoid.html

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

function draw() {
  background(255, 200, 200);
  translate(width/2, height/2);  // moving the drawing to center 

  drawEpitrochoid();
}

function drawEpitrochoid() {

    var n = 1500;          
    noFill();
    stroke(255);

    var x;
    var y;
    var h = constrain(mouseX, 0, 480); //distance between radius of smaller circle to the curve drawn (contrained and varied between left and right borders)
    var a = 300;    //radius of bigger circle
    var b = a/constrain(mouseY, 0, 480);  //radius of smaller circle (constrained to the left and right borders)


    beginShape();
        for (var i=0; i < n; i++) {

            var t = map(i, 0, n, 0, TWO_PI);

            var x = (a + b) * cos(t) - h * cos (((a+ b)/b)*t); //epitrochoid equation
            var y = (a + b) * sin(t) - h * sin (((a+ b)/b)*t); //epitrochoid equation
           
            vertex(x, y);
        }  
    endShape();
}

I really enjoyed playing around with all of the possible varying numbers in this project and am very pleased with the outcome. Moving your mouse very slowly throughout the canvas you’re able to see so many different beautiful designs made by the epitrochoid curves.

rfarn-project-07-curves

I started this project by simply creating basic curves. I started with the astroid curve.

However, I wasn’t inspired by this simple curve so I decided to explore some other curves. I came across the epitrochoid curve.

I decided to add a simple interaction, increasing the general radius as well as the loop sizes as the mouse moves from side to side. Then I added the astroid curve back on top as a little embellishment.

sketch

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

function draw() {
    background(36, 7, 26);
    translate(width/2, height/2); //moves curves from (0,0) center to center of canvas
    epitrochoid(); //draws epitrochoid curve
    astroid(); //draws radial astroid curve

}

function epitrochoid() {
    var b = 5; 
    var h = (b * 4) + mouseX/4; //change as mouse moves from side to side
    var a = 30 + mouseX/3;

    fill(107, 77, 87);
    strokeWeight(2);
    stroke(221, 200, 196);
    beginShape();
    for(var t = 0; t < 2 * PI; t += PI/500){ //1000 points along circle
        var x = (a + b) * cos(t) - h * cos(((a + b)/b) * t); //x coordinate
        var y = (a + b) * sin(t) - h * sin(((a + b)/b) * t); //y coordinate
        vertex(x, y);
    }
    endShape(CLOSE);
}

function astroid() {
    var a = 25 + mouseX/2; //changes as mouse moves from side to side

    noFill();
    strokeWeight(10);
    stroke(107, 77, 87);
    beginShape();
    for(var t = 0; t < 2 * PI; t += PI/500){ //1000 points along circle
        var x = a * pow(cos(t), 3); //x coordinate
        var y = a * pow(sin(t), 3); //y coordinate
        vertex(x, y);
    }
    endShape(CLOSE);
}

yoonyouk-project07-curves

sketch

//Yoon Young Kim
//Section E
//yoonyouk@andrew.cmu.edu
//Project07

var a = 50; //size of the rose curve
var nPoints = 100; //number of points on the curve

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

function drawRoseCurve() {
    background(207, 212, 255); // blue background color

    stroke(145, 85, 112); //dark purple outline color
    strokeWeight(5);
    fill(204, 120, 157); //dusky pink fill color

    var t; //theta of the equation
    
    push();
    beginShape();

    translate(width/2, height/2);
    for(i = 0; i<mouseX; i++){ //number of points drawn based on the movement of mouseX
        var t = map(i, 0, mouseX + 40, 0, TWO_PI); //polar equation for the Rose Curve

      
        var r;
        var n = 4; // number of petals - when n is even, the function turns to 2n, therefore will create 8 petals

        r = a*cos(n*t); // drawing the Rose curve
        
        x = r *cos(t); //converting from polar to Cartesian
        y = r *sin(t); //converting from polar to Cartesian
        vertex(x, y);

    }
    endShape();
    pop();

}

function mouseMoved() {
    a = a + 1; //increasing the size of the flower when the mouse moves
    if(a>200){
        a=50;
    }
    drawRoseCurve();
}

I thought it was originally difficult to plug in the curve equations since we had to consider radians and Cartesian vs. polar equations. I wanted to do a rose curve because I was interested in how the lines would loop around in a flower like shape. In order to integrate the mouse movement with my curve I used the map function in order to determine the number of points of my curve. Therefore, as you move the mouse back and forth the loops will draw or undraw depending on the movement. Unfortunately, I was still unable to figure out how to make the entire curve close properly.

ashleyc1-Section C-Project-07-Curves

sketch

//Ashley Chan
//Section C
//ashleyc1@andrew.cmu.edu
//Project-07-Curves

var width = 480;

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

}

function draw() {

    background(220);

    drawAstroid();
    drawRanunculoid();

}

//first "shape"
function drawAstroid() {

    var x; 
    var y;
    var b = 40; 

    stroke(255);
    strokeWeight(.5);
    noFill(0);
    beginShape();

    push();
    translate(width/2, height/2);
        for(var i = 0; i < 500; i ++) {

            //llows for lots of different ways shape is being drawn
            var theta = map(i, 0, width, constrain(mouseX, 0, 480) + 600, TWO_PI);

            //astroid parametric formulas
            x = (3 * b * cos(theta)) + (b * cos(3* theta));
            y = (3 * b * sin(theta)) - (b * sin(3* theta));

            vertex(x, y);

            }
            endShape(CLOSE);
            pop();
}

//second "shape"
function drawRanunculoid() {

    var x;
    var y;
    var a = 5; //scales shape

    stroke(200);
    strokeWeight(.5);
    beginShape();
    translate(width/2, height/2);
        for(var i = 0; i < 75; i ++) {

            var theta = map(i, 0, width, 2 * constrain(mouseX, 0, 480) + 600, TWO_PI);

            //ranunculoid parametric formulas
            x = a * (6 * cos(theta)) + (cos(6* theta));
            y = a * (6 * sin(theta)) - (sin(6* theta));

            vertex(x, y);

        }

        endShape(CLOSE);

    //same shape but bigger and falls outside of astroid
    beginShape();
        for(var i = 0; i < 75; i ++) {

            var theta = map(i, 0, width, 2 * constrain(mouseX, 0, 480) + 600, TWO_PI);

            x = 50 * (6 * cos(theta)) + (cos(6* theta));
            y = 50 * (6 * sin(theta)) - (sin(6* theta));

            vertex(x, y);

            }

            endShape(CLOSE);
        
}

I had a lot of fun with this project. My process was just a lot of exploring the different functions via mathworld and playing around with which functions look nice with one another. It was a nice refresher to look at math formulas and think about how they corresponded with the visual compositions it was creating. I also spent a lot of time learning about map() and how to draw complex “shapes” using vertex(). I think there’s a lot of potential of using math as a way to create compelling and dynamic visuals.

Some Stills:

mmirho – Project 07 – Curves

I fiddled with the math for a while, trying to identify a form I liked and eventually settled on a sort of an hourglass figure.

I connected lines from every point on the hourglass to the center of the figure to create a visually central effect, and then varied the rotation of the figure and the size of the figure on the X and Y coordinates of the mouse.

I then looped the figure to splay out at different speeds when rotating, to layer the image on top of itself in a simple and satisfying way. If you drag the rotation around enough, it starts to look like a clover!

The rotating pairs of cloverleafs also create an even more central effect on the overall image.

sketch

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

function draw() {
    
    stroke(100,200,100);

    background(210, 210, 255);
    fill(50, 100, 50, 70);

    for (var q = 500 ; q > 200 ; q -= 50) {

        push();
        translate(width/2, height/2);
        //Puts the hourglasses at the center of the canvas

        rotate(mouseY/q);
        //Rotates the individual hourglasses at a contantly
        //Increasing rate, so they seperate from each other

        hourglass();
        //Draws the hourglass
        pop();
    }
}

function hourglass() {

    beginShape();
    for (var i = 0; i < mouseX; i++) {

        var t = map(i, 0, mouseX/1.5, 0, TWO_PI);
        var a = i*4;

        var x = (a*sin(t)*cos(t))/t;
        var y = (a*sin(sin(t)))/t;
        //The mathematical equation needed to create the
        //reversing hourglass curve

        vertex(x,y);
        line(x,y,0,0);
        //Draws a line from the center of the figure to
        //Every point on the curve, creating a web-ish
        //effect that draws your eyes to the middle
        
        
    }
    endShape(CLOSE);
}

elizabew – Project – 07 – Composition with Curves

sketch

//Elizabeth Wang
//Section E
//elizabew@andrew.cmu.edu
//Project 07: Composition with Curves

var nPoints;
var angle;

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

function draw() {
  background(102,106,134);

  angle = map(mouseX, 0, mouseY, 0, 360);

  translate(width/2, height/2); //keeps shape centered

  push();
  rotate(angle);
  drawAstroidCurve(); //calls to function drawShape
  pop();
}


function drawAstroidCurve(){

  var a = map(mouseX, 20, mouseY, 20, 30);
  nPoints = map(mouseX, 0, mouseY, 0, 20);

  beginShape(); //prevents object from adding on top of itself
  for (i = 0; i < nPoints; i++){
  var xr;
  var yr;
  var qx;
  var qy;
  var t = map(i, 0, nPoints, 0, 360);
  //http://mathworld.wolfram.com/Astroid.html
  var x = a*pow(cos(t), 3); //astroid curve's parametric equations
  var y = a*pow(sin(t), 3);
  //http://mathworld.wolfram.com/AstroidRadialCurve.html
  xr = x + 12*a*cos(t)*pow(sin(t), 2); //quadrifolium of astroid curve
  yr = y + 12*a*pow(cos(t), 2)*sin(t);

  noFill();
  strokeWeight(1);
  vertex(xr + (-10, 5), yr + random(-10, 5)); //keeps the shape "shaking"
  stroke(255,180,162);
  ellipse(xr + (-10, 5), yr + random(-10, 5), 3,3); //shaking ellipses
  stroke(223,243,227);

  if ((i % 2 == 0) & (i > 1)) { //dotted line
            stroke(232,197,71);
            line(qx, qy, xr, yr);
        }
        qx = xr;
        qy = yr;

  }
   endShape(CLOSE);
}

Still images:

Reflection

For my curve, I ended up choosing the quadrifolium of the astroid radial curve. When I started, I had a lot of trouble with radians and ended up accidentally translating my entire shape to move around a circle. Finally when I figured out what I did wrong and changed radians to angle, I wanted to make my shape not only “shake”, but to make it more dynamic; so I added a “backdrop” of dotted lines to give my shape more depth while also adding shaking dots. Overall I’m really happy with how it turned out and it reminds me of installations that demonstrate the vibrations of sound and/or music.

Project-07-Chickoff-Checkered Shape

sketch

//Cora Hickoff
//Section D
//chickoff@andrew.cmu.edu
//Project-07

var nPoints = 100;
var CYCLOID = 0; 

var titles = ["<><><><><><><><><><><><><><><><><><><><>"];
var curveMode = CYCLOID;


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

function draw() {
    background(224, 200, 197, 90);

      for (var y = 0; y < height; y += 5) {
        for (var x = 0; x < width+25; x += 50) {
            fill(255, 240, 250, 20);
            ellipse(x, y, 10, 5);
        }
    }
    
    // draw the frame
    fill(200, 0, 0); 
    noStroke();
    text(titles[curveMode], mouseX / 3, mouseY / 3);
    stroke(0);

    fill(200, 0, 0); 
    noStroke();
    text(titles[curveMode], mouseX / 3, mouseX / 2);
    stroke(0);

    noFill(); 
    strokeWeight(0);
    rect(0, 0, width-1, height-1); 

    // draw the curve
    push();
    translate(width / 2, height / 2);
    switch (curveMode) {
    case CYCLOID:
        drawCycloidCurve();
        break;
    }
    pop();
}

//--------------------------------------------------
function drawCycloidCurve() {
    // Cycloid:
    // http://mathworld.wolfram.com/Cycloid.html

    var a = 9.0;
    var b = a / 3.0;
    var h = constrain(mouseY / 20.0, 80, b);
    var ph = mouseX / 50.0;
    
    fill(205, 20, 20, 90);
    strokeWeight(1);
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        
        x = b - 4 + (t - sin(t)) - h * sin(ph + t * (a * b) / b);
        y = b + (1 - cos(t)) - h * cos(h + t * (a + b) / b);

        //places curve in middle of canvas
        vertex(x - 12, y - 20);
    }
    endShape(CLOSE);

    var a = 9.0;
    var b = a / 6.0;
    var h = constrain(mouseY / 20.0, 80, b);
    var ph = mouseX / 50.0;
    
    fill(205, 160, 160, 200);
    noStroke();
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        
        x = b - 4 + (t - sin(t)) - h * sin(ph + t * 2 * (a * b) / b);
        y = b + (1 - cos(t)) - h * cos(h + t * (a + b) / b);

        //places curve in middle of canvas
        vertex(x - 12, y - 20);
    }
    endShape(CLOSE);
    
}

In this project, I wanted to make the final product very soothing to look at, as well as aesthetically pleasing. My process with this was to play around with color and shape until I got this result which uses the same shape twice but changes some attributes such as color, opacity, strokeWeight (or lack thereof).