Project 7: Composition with curves

sketch

// Yash Mittal
// Section D

nPoints = 100;

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


function drawLemniscateCurve () { // coding the curve

    var x;
    var y;

    var a = 180;
    var h = mouseX; // X axis interaction
    var w = map (mouseY, 0, 480, 0, 240) // Y axis interaction

    stroke (205, 0, 11);
    strokeWeight (5);
    fill (255);

    beginShape ();

    for (var i = 0; i < nPoints; i = i + 1) {

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

        x = (a * cos (t + w)) / (1 + pow(sin (t), 2)); // iterating x
        y = (a * sin (t + h)) * (cos (t)) / (1 + pow(sin (t), 2)); // iterating y

        vertex (x + w / 3, y + h / 3);
    }

    endShape (CLOSE);
}

function draw() { 

    background (0);

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


    }

After I chose my curve, I realized that it somewhat looks like Spiderman’s eyes from into the spider-verse and I wanted to experiment more with that so I tried to iterate different eyes based on the X and Y location of the mouse. I struggled with drawing the curve at first but once I understood the concept, iterating became pretty easy.

Project-07: Composition with Curves

Composition CurvesDownload
/*Name:Camellia(Siyun) Wang; 
Section: C; 
Email Address: siyunw@andrew.cmu.edu;*/


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

    nPoints = 100;
}


function draw() {
    background(245,222,179);
    push();
    translate(width / 2, height / 2);
    drawBulletnose();
    pop();
}

function drawBulletnose(){
    var x;
    var y;
    var a = constrain(mouseX / 2,0,200);
    var b = constrain(mouseY / 2,0,200);

    stroke(240,248,255);
    strokeWeight(5);
    fill(230,230,250);
    beginShape();
    for(var i = 1; i < nPoints; i++){
        var t  = map(i,0,nPoints,0,PI);
        //Bullet Nose
        x = a * cos(t);
        y = b * (1/tan(t));
        vertex(x,y);
    }
    for(var i = 1; i < nPoints; i++){
        var t  = map(i,0,nPoints,0,PI);
        //Bullet Nose
        x = -a * cos(t);
        y = b * (1/tan(t));
        vertex(x,y);
    }
    endShape();


}
   

When doing this assignment, I first browse through the given curve website to see which curve I am most interested in and can possibly create variation in it. When I chose to do the Bullet Nose, I looked at its x and y equation, then realized that to create variation of this form, I need to change t, a, and b. That’s why in my code, I defined a and b first in the draw function, and then defined t in the for loop to draw the shape. Then I set the a and b to be manipulated by mouseX and mouseY.

Bullet Nose 1: Largest MouseX and mouseY
Bullet Nose 2: mouseX smaller, mouseY smaller

LO: Information Visualisation

For this weeks blog, I chose to analyze a project called “Melting memories – Drawing neural mechanisms of cognitive control” by Refik Anadol Studios. This project revolves around visualizing brain activity of participants when they were asked to recall a specific childhood memory. This childhood memory is not mentioned but it’s really interesting to think how different elements of these memories will have visually different representations. The technical workings of how these memories were displayed in a visual way are quite complex and it was hard for me to understand but the basics is that researchers took EEG data from the participants brains and converted that data into 3D models that we see. This sort application of data visualization can have en enormous on our society in different fields like healthcare, education etc.

Link to the project – https://www.creativeapplications.net/vvvv/melting-memories-drawing-neural-mechanisms-of-cognitive-control/

Visualization of brain activity

Project 7: Curves

wpf-curves.js
//Patrick Fisher, Section B, wpf@andrew.cmu.edu Assignment -07-project
var functionState = 1;
function setup() {
    createCanvas(480, 480);
    frameRate(10);
}

function draw() {
    var nPoints = 80;
    var radius = 150;
    var separation = 120;

    if(functionState == 1){ //glitchy circle
        background(0);
        fill(255, 255, 255, 64);
        var mouseXincrease = map(mouseX,0,width,-40,40);
        var mouseYincrease = map(mouseY,0,height,-40,40);
        var colorXY = map(mouseX + mouseY,0,960,0,255);
    
        push();
    
        translate(2*separation, height / 2);
        fill(255,0,colorXY);
        beginShape();
        for (var i = 0; i < nPoints; i++) {
            var theta = map(i, 0, nPoints, 0, TWO_PI);
            var px = radius * cos(theta);
            var py = radius * sin(theta);
            vertex(px + random(-40, mouseXincrease), py + random(-40, mouseYincrease));
        }
        endShape(CLOSE);
        pop();
    } 

    else if(functionState == 2) {
        var mouseXpoints = map(mouseX,0,width/2,1,30);
        var oppoY = map(mouseY,0,width,255,0);

        background(240);
        push();
        fill(oppoY)
        translate(2*separation, height / 2);
        beginShape();
        for (var i = 0; i < mouseXpoints; i++) {
            var theta = map(i, 0, mouseXpoints, 0, TWO_PI);
            var px = radius * cos(theta);
            var py = radius * sin(theta);
            vertex(px,py); 
            ellipse(px, py, 3,3);
        }
        endShape(CLOSE);
        pop();
    }    
}

function mousePressed(){
    if(functionState ==1){
        functionState = 2;
    } else if(functionState ==2){
        functionState = 1;
    }
}

I am very conflicted on the result of this project. I had a major lack of inspiration when it came to ideas, so I ended up taking some of the shapes shown in the sample and playing around a bit with them. I had difficulty with some of my map functions as they were not working as I had intended for some reason. However, I do like in the end what I came up with. The circle getting more and more glitchy is really fun and I really love how the vertices of the second circle spring out of the original one like a clown car.

Looking Outwards 7

This week I am looking at a YouTube video called “SEIZURE WARNING Pushing Sorts to their Limits”. Hyperbolic name aside, it is an hour long video where YouTuber Musicombo visualizes 79 different sorting algorithms. All the arrays sorted just contain integer values, up to either 2^14th (roughly 8 thousand) or 2^15th (roughly 16 thousand), in a completely random order. All the algorithms are doing is comparing two number values and seeing which one is larger than the other, until eventually the array is sorted correctly from 1 to their max number. However, how each algorithm goes about where in the array it chooses to compare a pair of numbers is where the variety and artistry comes in. Some are very simple, such as starting in the middle and going down, then starting in the middle of the rest of the unsorted section, so on and so forth, while some are much more intricate. The intricate ones are not always the fastest, but they create the more interesting patterns and visuals for sorting. Additionally the creator adds fun, arcade, Pac-Man esk sounds that make the entire process very pleasant as the cluttered noise becomes closer to a solid sequence, culminating when the final check runs successfully. The idea is relatively simple but the execution is so remarkable that it is just so satisfying to watch, so much so that the video has over 1.6 million views.

Musicombo

Project 7: Composition with Curves

sketch

var x1;
var y1;
var x;
var y;
var a;
var t;
var r;
var g;
var b;
var bcolor;

function setup() {
    createCanvas(480, 480);
    let j = 700
    while (j > 0) {
        strokeWeight(0);
        j = j - 10
        bcolor = map(j, 700, 0, 0, 255);
        fill(bcolor);
        circle(240, 240, j);
    }
}

function draw() {
    stroke(r, g, b);
    strokeWeight(3);
    beginShape();
    for (var i = 0; i < 100; i++) {
        a = map(mouseX, 0, 480, 0, 100);
        t = map(mouseY, 0, 480, 0, 100);
        x1 = a * sin(t);
        y1 = a * sin(t) * cos(t);
        x = 240 + x1 * -1
        y = 240 + y1 * -1
        vertex(x, y);
        print(y);
    }
    endShape(CLOSE);
}

function mousePressed() {
    r = random(0, 255);
    g = random(0, 255);
    b = random(0, 255);
}

As I started working on this project, I wanted the viewer to be able to “draw” the curves themselves. As MouseX changes, the size of the curve changes. As MouseY changes, different points are added on the curve. When the canvas is clicked, the color of the points change. If you manipulate the mouse in a certain way, you can make concentric figure 8s of varying colors. When I finished coding the curves and their mouse interaction, it still felt a little bland, so I added a circular gradient to the background to focus the eye gaze on the center of the canvas.

Project – Cardioid Visualization

sketch
//Brandon Yi
//btyi@andrew.cmu.edu
//Section A

// Cardioid Function

var points = 200; // number of points on circle
var rate; // coefficient
var r = 180; // radius of big circle
var count = 0;

function setup(){
  createCanvas(400, 400);
  frameRate(200);
  rate = 2;
}

function draw() {
  //basic settings 
  background(0);
  translate(width/2, height/2);

  //  Large White Circle
  stroke(255);
  fill(0);
  ellipse(0, 0 , r * 2, r * 2);

  // drawing lines based on cardioid shape 

  for(var i = 0; i < count; i++){

    var x = r * cos(i * TWO_PI/points);
    var y = r * sin(i * TWO_PI/points);

    var x2 = r * cos(i*rate * TWO_PI/points);
    var y2 = r * sin(i*rate * TWO_PI/points);

    //color gradient based on rate

    if (rate % 3 == 0) {
      stroke(i, 0, 255-i);
    }

    else if (rate%3 == 1) {
      stroke(0, i, 255-i);
    }

    else {
      stroke(i, 255-i, 0);
    }
    // drawing line
    line(x, y, x2, y2);
  }  

  //counter increases until count of 200 lines
  if(count <= points) {
    count += 1;
    frameRate(200);
  }

  //counter hits 200 -- cardioid coefficient increases + counter reset
  else {
    rate++;
    count = 0;
  }

  // coefficient reset
  if (rate >= 12) {
    rate = 2;
  }

  // brief pause 
  if(count == points) {
    frameRate(1);
  }

  
}

I wanted to combine what we did with the line drawings and the new curves that we were trying to draw. Though it took some thinking, I think my project turned out really well.

Looking Outwards

One of the projects I found very interesting has to be the ones done by “Martin Wattenberg” to help better visualize the information being processed by machine learning. One of the scariest things about machine learning is the idea of separating the human from the machine. In a way, the concept of “self-learning” machines is a scary one too many people, and often is portrayed as the end of humanity in various movies and TV shows. However, using the visualizations by Wattenberg, we are able to better understand what goes on inside the machine learning code and what kinds of decisions are being made. On top of helping us better understand the inner workings of machine learning code, Wattenberg also created a way for engineers and scientists to learn about machine learning systems. The future of automation and the tech industry seems to revolve around machine learning; however, it takes a lot of prior computer science knowledge to fully understand it. With this visualization, Wattenberg has made it much easier to visualize and conceptualize the powers of machine learning.

Machine Learning Visualization
“Tensorflow Playground” – allows users to play with a neural network and understand machine learning

Project-7: Composition with Curves

My Project

//cbtruong;
//Section B;

//sets up the variables for stroke color;
//col is the stroke color for smooth conical spiral;
//col2 is the stroke color for the rough conical spiral;
var col = 0;
var col2 = 0;
//sets up the variable for angl to allow for rotation;
var angl = 0;
//sets up the variable for the shifting fill color value;
//for the rough conical spiral;
var shiftingVal = 100;
//sets up the variable that allows for reversing the change;
//of shiftingVal;
var shiftingValChange = 1;


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

function draw() {
    background(220);
    stroke(0);
    //diagonal lines that hit the center of the spirals;
    line(0, 0, 120, 120);
    line(0, 480, 120, 360);
    line(480, 0, 360, 120);
    line(480, 480, 360, 360);
    //lines that outline the perimeter of the canvas;
    line(0, 0, 480, 0);
    line(0, 0, 0, 480);
    line(480, 0, 480, 480);
    line(0, 480, 480, 480);
    //lines of the innerbox whose vertices are the spiral centers;
    line(120, 120, 120, 360);
    line(120, 360, 360, 360);
    line(360, 360, 360, 120);
    line(360, 120, 120, 120);

    //draws the middle, rough concial spiral;
    strokeWeight(2);
    fill(shiftingVal);
    stroke(col2);
    push();
    translate(240, 240);
    conicalSpiralTopViewRough();
    pop();
    
    //draws the 4 smooth rotating conical spirals;
    noFill();
    stroke(col);
    for (var i = 120; i <= 360; i += 240){
        for (var j = 120; j <= 360; j += 240){
            push();
            translate(j, i);
            rotate(radians(angl));
            scale(0.5);
            conicalSpiralTopViewSmooth();
            pop();
        }
    }

    //checks if the shiftingVal is too high or low;
    //if too high, the fill becomes darker;
    //if too low, the fill becomes ligher;
    if (shiftingVal >= 255){
        shiftingValChange = shiftingValChange * -1;
    }
    else if (shiftingVal < 100){
        shiftingValChange = shiftingValChange * -1;
    }
    //changes the shiftingVal;
    shiftingVal += 1*shiftingValChange;
    //changes the angle and allows for rotation;
    //of the smooth conical spirals;
    angl += 0.1;
    

}

//function that creates the smooth conical spirals;
function conicalSpiralTopViewSmooth() {
    //variables for h, height; a, angle; r, radius;
    var h = 1;
    var a;
    var r = 30;
    
    //adds interactivity;
    //as one goes right, the size of the spiral increases;
    //as one goes down, the complexity of the spiral increases;
    var indepChangeX = map(mouseX, 0, 480, 500, 1000);
    var indepChangeY = map(mouseY, 0, 480, 800, 1000);
    a = indepChangeY;

    //actually creates the spiral;
    beginShape();
    for (var i = 0; i < indepChangeX; i++){
        var z = map(i, 0, 400, 0, PI);
        x = ((h - z) / h)*r*cos(radians(a*z));
        y = ((h - z) / h)*r*sin(radians(a*z));
        vertex(x, y);
    }
    endShape(CLOSE);

}

//function that creates the rough middle conical spiral;
function conicalSpiralTopViewRough() {
    //variables are the same as the smoothSpiral function;
    var h = 0.5;
    var a = 1000;
    var r;
    
    //adds interactivity;
    //the radius is now dependant on mouseY, going up increases size;
    //going left increases complexity;
    r = map(mouseY, 0, 480, 20, 10);
    var edgeNum = map(mouseX, 0, 480, 60, 30);
    
    //creates the spiral;
    beginShape();
    for (var i = 0; i < edgeNum; i++){
        var z = map(i, 0, 50, 0, TWO_PI);
        x = ((h - z) / h)*r*cos(radians(a*z));
        y = ((h - z) / h)*r*sin(radians(a*z));
        vertex(x, y);
    }
    endShape();
}

//mousePressed function that changes the variables col and col2;
//with random values of r, g, and b;
function mousePressed() {
    var randR = random(150);
    var randG = random(150);
    var randB = random(150);
    col = color(randR, randG, randB);
    col2 = color(randR + random(-50, 50), randG + random(-50, 50), randB + random(-50, 50));
}

I initially had no idea what to make in terms of curves. That was until I happened upon the Conical Spiral. It was supposed to be 3-D, but it ended up as a top down view of a spiral which I liked. Overall, I liked what I did with this Project.

As for how it works, clicking the mouse will change the colors of the middle “rough” Conical Spiral and the 4 “smooth” Conical Spirals. The colors of both types are similar but not the same, as seen with the use of random() in the code.

Along with that, moving the mouse right will increase the size of the “smooth” Spirals and reduce the size and complexity of the “rough” Spiral. Moving left does the opposite. Moving down increases the complexity of the “smooth” Spirals while also reducing the size of them and the “rough” Spiral.

LO 7: Information Visualization

Juan Francisco Saldarriaga’s CitiBike Rebalancing Study is a investigation and subsequent data visualization to assist CitiBike with maintaining the equilibrium of their bike stations throughout different locations and times of day. The matrix is organized on those two axes, location and time of day, to establish patterns of usage. The imbalance of bikes is demonstrated by color, blue and orange, while the overall usage is characterized by the brightness of the color. This visualization makes it immediately apparent which stations are consistently depleted or overloaded daily. The analysis of this data will allow CitiBike to partially automate their system of organization, significantly cutting labor and expenses from the inefficient old system, which was based almost randomly on urgent need.