Project 7 Curves

This is my project: the left and right mouse movements change the number of curves and the up and down spins the objects. Clicking the mouse changes the type of circle on the outside of the rose curve.

sketch
//Michael Li
//Section C 

//set variables for points
var points = 100;
//set variable for state machine
var type = 0


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


function draw() {
    background(50);
    //add text
    text("Click to change shape", 20, 30)
    //move to the center of the canvas
    translate(width/2,  height/2)
    
    //to change the shapes between spiral and flower
    if (type == 0){
    spiral() //spiral function
    } else if(type == 1){
        //repeat the function for flower
        for(var i = 0; i <5; i++){
            //different state
            drawEpitrochoid(i) 
        }
    } 
    //draw center flower
    drawRoseCurve();


}

function drawRoseCurve() {
    // RoseCurve
    //constrain the mouse within the canvas
    var conMX = (constrain(mouseX, 0, width))
    var conMY = (constrain(mouseY, 0, width))
    //map the height of the rosecurve
    var h = map(conMY, 0, width, width*1/5, width*2/5)

    var x;
    var y;
    //map the color to the mouse movement
    var mapColorX = map(mouseX, 0, width, 100, 255)
    var mapColorY = map(mouseY, 0, width, 100, 255)
    //the color of the rosecurve changes depending on the outer elements
    if(type == 0){
        //blue and orange
        var c = color(mapColorX, mapColorX/2+mapColorY/2, mapColorY)
    } else if (type == 1){
        //green and purple
        var c = color(mapColorX/2+mapColorY/2, mapColorY, mapColorX)
    }
    var r; 
    //have the variable n only store odd numbers for better rose curve
    var n = printOdd(int(map(conMX, 0, width, 3, 20)))
    
    noFill()
    strokeWeight(1)
    stroke(255)
    circle(0, 0, h*2)
    fill(c)
    stroke(c);
    //draw rose curve
    beginShape();
        for (var i = 0; i < points; i++) {
            var theta = map(i, 0, points, 0, PI);
        
            r = h*cos(theta*n)
            x = r*cos(theta+conMY)
            y = r*sin(theta+conMY)
            curveVertex(x, y);

        }
    endShape(CLOSE)
}

//draw spiral
function spiral(){
    //constrain mouse within the canvas
    var conMY = (constrain(mouseY, 0, width))
    //map value to mouseY
    var a = map(conMY, 0, width, width*1/5, width*2/5)
    
    var x;
    var y;
    var r;

    noFill()
    push()
    beginShape()
    //map number of points to mouse Y
    //spiral grows as mouseY moves
    var mapYPoints = map(mouseY, 0, height, 25, 100)
        //draw spiral
        for (var u = 0; u < mapYPoints; u++) {
            //theta depend on mouse Y
            //spiral spins
            var theta = map(u, 0, mapYPoints/10, 0, TWO_PI);
            //circle size depend on mouseY
            var mapSize = map(u, 0, mapYPoints, 40, 10)
            r = ((theta)**(1/2))*a/4
            x = r*cos(theta+10)
            y = r*sin(theta+10)

            curveVertex(x, y)
            stroke(255-u*4)
            fill(255-u*4)
            //draw circles on the spiral
            circle (x, y, mapSize/2)
            stroke(200)
            noFill()
        }
    endShape()
}
//draww epitrochoid
function drawEpitrochoid(rot){
    push()
    //constrain mouseX and mouseY
    var conMX = (constrain(mouseX, 0, width))
    var conMY = (constrain(mouseY, 0, width))
    var a = map(conMY, 0, width, width*1/5, width*2/5)
    var b = constrain(a / int(conMX / 30), 0, 20)
print(a)
    var x;
    var y;

    //rotates the shape each loop
    rotate(rot+conMY/10)
    noFill()
    stroke(200)
    push()
    beginShape()
    //fill the shape with lower opacity to create layering effect
    fill(200, 200, 200, 50)
    var mapYPoints = map(mouseY, 0, height, 0, 25)
    //draw epitrochoid
        for (var u = 0; u < 100; u++) {
            var theta = map(u, 0, 100, 0, TWO_PI);

            x = rot/2*(a+b)*cos(theta)-b*cos(((a+b)/b)*theta);
            y = rot/2*(a+b)*sin(theta)-b*sin(((a+b)/b)*theta);
            curveVertex(x, y)

            
        }
    endShape(CLOSE)
    pop()
}
//only store odd numbers in a variable
function printOdd(x){

    if(x%2 == 0){
        return x-1
    } else{
        return x
    }
}
//swtich the type when mouse pressed

function mousePressed() {
    type += 1
    if(type > 1){
        type = 0
    }
}

Project 7: Curves

Abstract roses using astroids and astroid evolutes. Astroids rotate using mouseX and scale using the minimum of mouseX and mouse Y. Random astroids are added to the canvas. The color of these depends on the mouse’s position on the canvas. If left on canvas they are red, and if on right of canvas they are black. Moving mouse along diagonals creates and in bottom right corner creates best shapes.

sketch – Copy – Copy – Copy
// Ana Furtado 
// Section E
// Project 7 Composition with Curves

var nPoints = 100;

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

function draw() {
    
    strokeWeight(3);

    //rotates and scales by mouse at top right
    //brown/red at left and bottom
    push();
    translate(width/4, height/4);
    scale(mouseX/width);
    rotate(radians(min(mouseX,mouseY)));
    drawAstroid();
    if (mouseX < width/2) {
        stroke('brown'); 
        rotate(radians(min(mouseX,mouseY)));
        drawAstroid();
    } 
    pop();

    //rotates and scales by mouse at bottom left
    //brown/red at left and bottom
    push();
    //translate(width/2, height/2)
    translate(width/4 * 3, height/4 * 3);
    scale(mouseX/width);
    rotate(radians(min(mouseX,mouseY)));
    drawAstroid();
    if (mouseX < width/2) {
        stroke('brown'); 
        rotate(radians(min(mouseX,mouseY)));
        drawAstroid();
    } if (mouseY > height/2) {
        stroke('brown'); 
        rotate(radians(min(mouseX,mouseY)));
        drawAstroid();
    }
    pop();

    //rotates and scales by mouse at random location 
    //move/leve mouse to left of canvas for red atroids 
    //move/leave mouse to right of canvas for black atroids 
    //move/leave in top right of canvas to fill with more black atroids
    push();
    translate(random(0,480), random(0,480));
    scale(0.5);
    rotate(radians(min(mouseX,mouseY)));
    drawAstroid();
    if ( mouseX < width/2) {
        stroke('brown'); 
        rotate(radians(min(mouseX,mouseY)));
        drawAstroid();
    }
    pop();

    

    //originals that stay in  splace
    //only show in beginning
    //scaled and rotated turns the astroid into an atroid evolute
    push();
    translate(width/2, height/2);
    drawAstroid();
    pop();

    //stays in place scale 0.5
    push();
    translate(width/2, height/2);
    scale(0.5);
    rotate(radians(45));
    drawAstroid();
    pop();

    //stays in place scale 0.25
    push();
    translate(width/2, height/2);
    scale(0.25);
    rotate(radians(45));
    drawAstroid();
    pop();

}

function drawAstroid() {
    //Astroid
    //https://mathworld.wolfram.com/AstroidEvolute.html

    var x;
    var y;
    var a = 300;

    //fill('pink');
    noFill();
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        //angleMode(DEGREES);
        x = a * (cos(t) * cos(t) * cos(t));
        y = a * (sin(t) * sin(t) * sin(t));
        vertex(x, y);
    }
    endShape(CLOSE);
    constrain(a, 0, 325);
}

I think the most difficult part of this was getting the shape to be represented properly.

Project-07: Composition with Curves

sketchDownload
//Alicia Kim
//yoonbink@andrew.cmu.edu
//Section B

var nPoints = 100;
var r;

function setup() {
    createCanvas(480, 480);
    background(220);
    
    r=0;

    
}

function draw() {

// gradient background (adapted from my project 6)
    for(var j=0; j<height; j+=1) {
        stroke(lerpColor(color(127,255,212) ,color(255,253,208),j/height));
        line(0,j,width,j);
    }

    noStroke();

    push();
    translate (width/2, height/2); 

    noFill();
    if (r<=15){
        r+=0.17;
    }
    else{r=0}
    drawHeart2(r);
    drawDevil();
    pop();

    drawHeart1();
}

function drawDevil() {
    // https://mathworld.wolfram.com/DevilsCurve.html
    // adapted from drawCranoid example from Wk 7 Deliverable example

    
    var x;
    var y;

    
    
    fill(250,250,210);
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        
      
        var a = constrain((mouseX / width), -16.0, 16.0);
        var b = constrain((mouseY / height), -16.0, 16.0);
        var t = map(i, 0, nPoints, 0, TWO_PI);
    

        x = 100*cos(t)*sqrt((sq(a)*sq(sin(t))-(sq(b)*sq(cos(t)))/(sq(sin(t))-sq(cos(t)))));
        y = 100*sin(t)*sqrt((sq(a)*sq(sin(t))-(sq(b)*sq(cos(t)))/(sq(sin(t))-sq(cos(t)))));
        vertex(x, y);
    }
    endShape();
}

//cursor  heart
function drawHeart1(){

    var x2;
    var y2;

    fill(250);
    beginShape();
    for (var j = 0; j < nPoints; j++) {
     
        var t2 = map(j, 0, nPoints, 0, TWO_PI);
        

        x2 = mouseX+2*16*pow(sin(t2),3);
        y2 = 2*(13*cos(t2)-5*cos(2*t2)-2*cos(3*t2)-cos(4*t2));
        y2= mouseY-y2 
        vertex(x2, y2);
    }
    endShape();
}

//background heart
function drawHeart2(r){

    var x3;
    var y3;
    // var r;
    fill(173,216,230);
    beginShape();
    // r=10;
    // r+=1;
    
    for (var j = 0; j < nPoints; j++) {
        
        var t2 = map(j, 0, nPoints, 0, TWO_PI);
        

        x3 = r*16*pow(sin(t2),3);
        y3 = -r*(13*cos(t2)-5*cos(2*t2)-2*cos(3*t2)-cos(4*t2));
      
        vertex(x3, y3);
    }
    endShape();
}

Project 07- Curves

Graham Murtha

Section A

For this project, I wanted to make a series of layered petal-like formations with linework, all with different reactions to mouseX and mouseY. However, the cardioid caused some trouble, since despite how many times I manipulated the equation, it remained an very slow-growing shape on the left of the screen.

sketch
//Graham Murtha
//Section A
//Assignment 7
//gmurtha@andrew.cmu.edu


var vertices = 150; // number of vertices or coordinates

function setup() {
    createCanvas(480, 480);
    background(0);
    text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
    push();
    //moves origin to the center of the canvas
    translate(width/2,height/2);

    //draws loop for the three shapes

    background(120,0,60);// dark magenta-red
    Ranunculoid();
    Cardioid();
    Nephroid();
    pop();
}

function Ranunculoid(){
    //https://mathworld.wolfram.com/Ranunculoid.html
    
    //variables
    var x;
    var y;
    var a = mouseX/7
    var b = mouseY/100
    
    beginShape();
    noFill();
    stroke(255,180,255);  //light purple
    for(var i=0; i<vertices; i++){ // parametric equations
            var Ag = map(i,0,vertices,0,TWO_PI); // angle/theta
            x = a*((6*cos(Ag))-(b*cos(6*Ag)));
            y = a*((6*sin(Ag))-(b*sin(6*Ag)));
            vertex(x,y);
            
        endShape(CLOSE);
    }
}

function Cardioid(){ 
    //https://mathworld.wolfram.com/Cardioid.html
    
    //variables
    var x;
    var y;
    var a = mouseX/4
    var b = mouseY/30
    
    beginShape();
    noFill();
    stroke(255,150,0);//orange
    for(var i=0; i<vertices; i++){ // parametric equations
            var Ag = map(i,0,vertices,0,PI+QUARTER_PI); // angle/theta
            x = (a*cos(Ag)*(1-cos(Ag))*b);
            y = (a*sin(Ag)*(1-cos(Ag))*b);
            vertex(x,y);
            
        endShape(CLOSE);
    }
}

function Nephroid(){
    // https://mathworld.wolfram.com/Nephroid.html
    
    //variables
    var x;
    var y;
    var a = mouseX/6
    var b = mouseY/4
    
    beginShape();
    noFill();
    stroke(255); // white
    for(var i=0; i<vertices; i++){ // parametric equations
            var Ag = map(i,0,vertices,0,PI); // angle/theta
            x = a*(3*cos(Ag))-((cos(3*Ag))*b);
            y = a*(3*sin(Ag))-((sin(3*Ag))*b);
            vertex(x,y);
            
        endShape(CLOSE);
    }
}

Project 07: Curves

This is my floral composition based on mathematical curves and reacts to the mouse’s location on the canvas.

sketch
/*
    Joan Lee
    Section D

    This program draws an interactive floral composition with mathematical curves.
*/

var nPoints = 400;

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


function draw() {
    background(28,92,76);    //dark green
    
    //drawing flower curve
    push();
    translate(width/2, height/2);
    drawCardioidCurve();
    pop();

    //drawing leaves curve
    push();
    translate(width/2, height/2);
    drawHypotrochoidCurve();
    pop();

}

//--------------------------------------------------
function drawCardioidCurve() {
    //cardioid curve
    push();
    translate(x, y);
    rotate(radians(90));
    var x = constrain(mouseX, 0, width);
    var y = constrain(mouseY, 0, height);
    var a = map(x, 0, width, 0, 40);
    var b = a/2;
   
    //mouse movement interaction
    if (mouseY > height/2) {    //color change
        fill(244,52,4);     //bright red
    } else {
        fill(252,156,132);  //pink
    }

    //cardioid curve parametric equations
    beginShape();
    noStroke();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);

        x = a * (6 * cos(t) - cos(6 * t));
        y = a * (6 * sin(t) - sin(6 *t));
        vertex(x, y);
    }
    endShape(CLOSE);
    pop();
    
}

//--------------------------------------------------
function drawHypotrochoidCurve() {
    //hypotrochoid curve
    noFill();
    strokeWeight(1);

    //mouse movement interaction

    if (mouseX < width/2) {      //color change
        stroke(4,220,156);  // bright green
    } else {
        stroke(204,236,228);    //pale green
    }

    var x = constrain(mouseX, 0, width);
    var y = constrain(mouseY, 0, height);
    var a = map(x, 0, width, 50, 150);
    var b = map(y, 0, height, 1, 6);
    var h = constrain(mouseY, 50, 90);
    
    //hypotrochoid curve parametric equations
    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);
    
}

Dynamic Snowflakes

For this project I used the rose curves and epicycloid functions to create this composition. The rose curve (white) resembles a snow flake and as the mouse moves the it changes but still looks like a snow flake. When mouse is at zero, the middle of the composition, 480 or off the canvas it creates a circle. The epicycloid changes in complexity and in color as the mouse moves.

sketch
//Nakshatra Menon
//Section C

var nPoints = 240;



function setup() {
    createCanvas(480, 480);
    background(246, 242, 240);
    colorMode(HSB);
}



function draw() {
    background("black");
    translate (width/2, height/2); // origin is middle of canvas 
    noFill();
    epicycloid(0, 0);             // shape 1
    roseCurve(0,0);               // shape 2 
}

function roseCurve(){  // draw rose curve from https://mathworld.wolfram.com/RoseCurve.html
    var g = constrain(mouseY/32, 5, 15);      // g is based on mouse Y
    var n = constrain(int(mouseX), 0, 480);   // n is based on mouse X
    strokeWeight(.5);
    stroke("white");
    beginShape();
    for (var i = 0; i < nPoints; i++) {
        var t = map(i, 0, nPoints, 0, TWO_PI);
        var radius = 10 * cos(n * t);    // function 

        // first set of values 
        var x = g*radius * cos(t);       // function 
        var y = g*radius * sin(t);       // function 

        // second set of values 
        var x1 = 2*g*radius * cos(t);    // function 
        var y1 = 2*g*radius * sin(t);    // function 

        vertex(x, y);                    // vertex for shape
        vertex(x1, y1);                  // vertex 2 for shape 
    }
    endShape(CLOSE);
}  

function epicycloid (){    // draw the epicycloid from https://mathworld.wolfram.com/Epicycloid.html
    var f = constrain(int(mouseY/20), 2, 48);        // output of number based on mouse Y
    strokeWeight(1);
    stroke(332,mouseX/5, 20);                        // color changes based on mouse X position 
    for (var a = 10; a <240; a = a+10){              // how many epicycloids are drawn 
        var b = a/f                                  // b is related to mouse Y
        beginShape();
        for (var i = 0; i < nPoints; i++) {
            var t = map(i, 0, nPoints, 0, TWO_PI);  // remaps 

            var x = (a+b)*cos(t) - b*cos(((a+b)/b)*t); // function 
            var y = (a+b)*sin(t) - b*sin(((a+b)/b)*t); // function 

            vertex(x, y);                              // vertex for points 
        }

    endShape(CLOSE); 
    }  
}









Curve

This is my curve project. I am using mouseX to control the rotation, scale, and color of curves while using mouseY to control the number of iterations. Also, when you click, the curve changes. I really like how Hypocychoid and Epitrochoid are constructed and how different iterations of them overlap one another.

Different iterations for Hypocychoid

Hypocycloid

//Jason Jiang
//Section E

//Setting up variables
var nPts = 200;
var a = 80;
var N;
var b
var x;
var y;
var crvMode = 1;


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


function draw() { 
    //Mapping mouseY value to number of iterations
    N = map(mouseY, 0, height, 0, 25);
    b = a/N;
    background(0);

    //Draw Hypocychoid
    if (crvMode%2 == 0) {
    for(var i = 3; i <= N; i++) {
        //Decreasing strokeWeight each iteration
        strokeWeight(2-i*0.05)

        //Changing color according to mouseX
        stroke(255-mouseX*0.1, 100-i, 200-i*5)
        crv1(i);
        stroke(255-mouseX*0.1, 100-i, 100-i*5)
        crv1(PI+i);
    }
}   
    //Draw Epitrochoid
    else {
        for(var i = 3; i <= N; i++){ 
            //Decreasing strokeWeight each iteration
            strokeWeight(2-i*0.05)
        
            //Changing color according to mouseX
            stroke(mouseX*0.1, 100-i, 200-i*5)
            crv2(i);
            stroke(mouseX*0.1, 100-i, 100-i*5)
            crv2(PI+i);
        }
    }
}

//Hypocychoid
function crv1(m) {
    //Changing scale and rotation according to mouseX
    h = map(mouseX, 0, width, 1, 2, true)*m*0.05;
    angle = map(mouseX, 0, width, 0, PI);
   
    push()
    translate(width/2, height/2);
    
    //Rotate curve according to mouseX
    rotate(angle + m);

    //Drawing curves
    noFill();
    beginShape()
    
        for(var i = 0; i < nPts; i++){
            var t1 = map(i, 0, nPts, 0, TWO_PI)
            var t2 = t1*(a-b)/b
            x = h*((a-b)*cos(t1)+b*cos(t2))
            y = h*((a-b)*sin(t1)-b*sin(t2))

            //Adding random movement to the curve
            vertex(random(x+4, x-4), random(y+4, y-4));
        }
    endShape(CLOSE);
    pop();
}

//Epitrochoid
function crv2(m) {
    //Changing scale and rotation according to mouseX
    h = map(mouseX, 0, width, 1, 2, true)*m*0.05;
    angle = map(mouseX, 0, width, 0, TWO_PI);
    
    push()
    translate(width/2, height/2);

    //Rotate curve according to mouseX
    rotate(angle + m);

    //Drawing curves
    noFill();
    beginShape()

        for(var i = 0; i < nPts; i++){
            var t1 = map(i, 0, nPts, 0, TWO_PI)
            var t2 = t1*(a-b)/b
            x = h*((a-b)*cos(t1)+b*sin(t2))
            y = h*((a-b)*sin(t1)-b*cos(t2))
            vertex(x, y);
        }
    endShape(CLOSE)
    pop();
}

//Change curves when press mouse
function mousePressed(){
   crvMode++
   print(crvMode);
}
    

Project 7

sketch
//Paul
//kengpul
//Section A
var x;
var y;
var circ = [];
// determines the line and size of the circle creating the circle w line inside
var drawingLine;
var lineDeg = 0;
var circleDeg = 0;
var colorStep = 0;
var colorStep2 = 0;

function setup() {
    createCanvas(480, 480);
    background(random(50,70),100,random(150,256));
}


function draw() {
    //creating perilin colors
    //cghanges size of the elements based on mouse y
    drawingLine = map(mouseY,0,height,20,height/5)
    //background(240,170,20);
    push();
    translate(width/2,height/2);
    rotate(radians(circleDeg));
    bigCirc();
    pop();
    circleDeg += map(5,0,width/2,0,drawingLine)*1.5;

    
    colorStep = colorStep += 0.01;
    colorStep2 = colorStep2 += 0.005;

}



//two functions under creates a line that spins 
//according to the center of the circle created in bigCirc(), this is done to replicate 
//the effect of an Astroid but with an interactive twist

function insideLine(){
    push();
    stroke(100,255,100);
    strokeWeight(1);
    //moves origin to center and top so the lines can rotate as it should
    translate(width/2-drawingLine,drawingLine/2+drawingLine*2);
    rotate(radians(lineDeg));
    line(0,0,0,drawingLine/2);
    strokeWeight(7);
    var pointCol = 255 * noise(colorStep2);
    stroke(pointCol,10,10);
    point(0,drawingLine*2);
    pop();
    //changes how "circular" the dots are printed 
    lineDeg += map(mouseX,0,width,0,5);
}

function bigCirc(){
    noFill();
    strokeWeight(1.5);

    //rgb value created with noise so each color doesnt vary too much circle to circle
    var r = 255 * noise(colorStep+5);
    var g = 255 * noise(colorStep+15);
    var b = 255 * noise(colorStep+20);
    stroke(r,g,b);
    circle(width/2-drawingLine,drawingLine/2+drawingLine*2,100);
    insideLine();
    //rotates the insideLine inside the circ
}
//when clicked , canvas resets with diff background so the program doesnt over crowd
function mousePressed(){
   background(random(50,70),100,random(150,256));
}


Project-07: Composition with Curves

sketch curveDownload
/*
Sandy Youssef; 
section D; 
syoussef@andrew.cmu.edu;
Project-07;
*/

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

function draw() {
    // Epicloid Curve
    //https://mathworld.wolfram.com/Epicycloid.html
    background(255);
    drawEpicloid1();
    drawEpicloid2();
    drawEpicloid3(); 
    drawEpicloid4();
    drawEpicloid5();
    drawEpicloid6();
    drawEpicloid7();
    drawEpicloid8();


}

function drawEpicloid1() {
//curve located at the top right that moves according to mouse Y 
push();
    translate( width/2-100, height/2-100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle that moves around bigger circle to create points
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseY/50
    fill(255, 0, 0, 50); // transparent pink
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(theta) - b * cos (theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (theta) - b * sin (theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();

}

function drawEpicloid2() {
// same curve as drawEpicloid1 but moves in opposite direction
push();
    translate( width/2-100, height/2-100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseY/50
    fill(200, 210, 0,50); //transparent yellow
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(-theta) - b * cos (-theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (-theta) - b * sin (-theta * (a + b) /b * move);
        vertex(x,y);
    
    }
    endShape(CLOSE);
    pop();

}

function drawEpicloid3() {
// curve located at top right that moves according to mouse X
push();
    translate( width/2+100, height/2-100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseX/50
    fill(200, 210, 0,50); // transparent yellow
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(theta) - b * cos (theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (theta) - b * sin (theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();

}

function drawEpicloid4() {
// same curve as drawEpicloid3 but moves in opposite direction according to mouse X
push();
    translate( width/2+100, height/2-100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseX/50
    fill(200, 0, 0,100); // brighter pink
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(-theta) - b * cos (-theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (-theta) - b * sin (-theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();

}

function drawEpicloid5() {
// curve located in bottom right corner that moves according to mouse Y
push();
    translate( width/2+100, height/2+100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseY/50
    fill(200, 210, 0,50); // transparent yellow
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(theta) - b * cos (theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (theta) - b * sin (theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();

}

function drawEpicloid6() {
// same curve as drawEpicloid5 but moves in opposite direction according to mouse Y
push();
    translate( width/2+100, height/2+100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseY/50
    fill(0, 210, 0,50); // transparent green
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(-theta) - b * cos (-theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (-theta) - b * sin (-theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();
}

function drawEpicloid7() {
// curve located in bottom left corner that moves according to mouse X
push();
    translate( width/2-100, height/2+100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseX/50
    fill(0, 250, 0,130); // brighter transparent green
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(theta) - b * cos (theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (theta) - b * sin (theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();

}

function drawEpicloid8() {
// same curve as drawEpicloid7 but moves in opposite direction according to mouse X
push();
    translate( width/2-100, height/2+100);
    var x; 
    var y; 

    var a = 20;; // radius of smaller circle 
    var b = a * 3;  // radius
    var theta = 30;
    var move = mouseX/50
    fill(200, 210, 0,50); //transparent yellow
    beginShape();
    for (var i = 0; i < 100; i ++) {
        var theta = map ( i , 0, 100, 0, TWO_PI);
        x = (a + b) * cos(-theta) - b * cos (-theta * (a + b) /b * move);  // mathematical formula for the curve
        y = (a + b) * sin (-theta) - b * sin (-theta * (a + b) /b * move);
        vertex(x,y);
    }
    endShape(CLOSE);
    pop();
}

Project-07-Curves

Astroid

sketch
//Brody Ploeger
//Section C
//jploeger@andrew.cmu.edu
//Project-07


var nPoints = 150
function setup() {
    createCanvas(480, 480);
    background(220);
    //text("p5.js vers 0.9.0 test.", 10, 15);
}

function draw() {
    background(0);

    push();
    translate(width/2,height/2)
    //astroid 1
    stroke('orange')
    noFill()
    astroid(0,0);
    //astroid 2
    stroke('lightblue')
    noFill()
    astroid2(0,0);
    pop();
}

function astroid(x,y,q,w){
    //https://mathworld.wolfram.com/Astroid.html
    var x;
    var y;
    

    var q = map(mouseX,0,width,0,5);
    var a = constrain(mouseX,0,width/2);
    var b = constrain(mouseY,0,height/2);
    var w = constrain(mouseY,0,height);

//shape
    beginShape();
    for (var i = 0; i<nPoints; i++){
        var t = map(i,0,nPoints,0,TWO_PI)
        
        x= a*pow(cos(t*w),3)
        y= b*pow(sin(t*w),3)
        rotate(radians(q))
        vertex(x,y);
    }
    endShape(CLOSE);





}
function astroid2(x,y,q,w){
    //https://mathworld.wolfram.com/Astroid.html
    var x;
    var y;
    

    var q = map(mouseX,0,width,0,5);
    var a = constrain(mouseX,0,width/2);
    var b = constrain(mouseY,0,height/2);
    var w = constrain(mouseX,0,height);

//shape
    beginShape();
    for (var i = 0; i<nPoints; i++){
        var t = map(i,0,nPoints,0,TWO_PI)
        
        x= a*pow(cos(t*w),3)
        y= b*pow(sin(t*w),3)
        rotate(radians(q))
        vertex(x,y);
    }
    endShape(CLOSE);





}