Ziningy1 – Section C – Project 03 – Dynamic Drawing

Inspired by how planets in solar system orbit around the sun, I made the visualization base on orbiting and pulsing movement. The aspects of image elements that the mouse movement controls include: background color, planet color, halo size(sun), the self-orbiting speed(moon), the stroke weight of the connecting line. I utilized a lot of sin() and cos() in this project to make the change more dynamic instead of one way. It is also my first time experimenting with the time elements in programing to create graphics.

ziningy1 – project 03

//Zining Ye 
//15104 lecture 1 recitation C
//ziningy1@andrew.cmu.edu 
//Project-03   

var sunx = 300
var suny = 240
var sunw = 130
var sunh = 130
var t = 1; //time





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

    
} 



function draw() { 
   

    angleMode(DEGREES); 

    background(32,50,74+(mouseX-mouseY)/13);
 
    noStroke();

    //multiple pulsing halo 

    fill(50+mouseY,100+mouseX,0,30);

    ellipse(sunx,suny,sunw+50*cos(-mouseX)+50,sunh+50*cos(-mouseX)+50); //halo changes size and color with the mouse moverment 

    fill(100+mouseX,mouseX/2,30,40);

    ellipse(sunx,suny,sunw+20*sin(mouseY)+40,sunh+20*sin(mouseY)+40); 

    fill(150+mouseY,mouseY,30,70);

    ellipse(sunx,suny,sunw+20*cos(mouseX)+10,sunh+20*cos(mouseX)+20); 


    

   
    
  

    //mercury, closest ball to the sun

    var merx = 100*cos(mouseX)+sunx 
    var mery = 100*sin(mouseX)+suny // the x, y coordinates of the first circle will move in a circle with the mouse movement, same for other orbiting circle


    fill(60+mouseX/2);

    stroke(210);
    strokeWeight(1+7*sin(mouseX)); //stroke line of the first orbiting ball changes with the mouse 
    line(merx,mery,sunx,suny);

    strokeWeight(2);
    ellipse(merx, mery, 20, 20);



    //venice 

    var venx = 140*cos(0.5*mouseX)+sunx //same with the first ball 
    var veny = 140*sin(0.5*mouseX)+suny

    fill(150+mouseX,mouseX/4,20);

    stroke(180);
    strokeWeight(1+5*sin(-mouseY));
    line(venx,veny,sunx,suny);

    strokeWeight(1+10*sin(-mouseY))

    ellipse(venx, veny, 30, 30);



    // earth

    fill(40,40+mouseY,100+mouseX);


    var earthX = 190*cos(-mouseX)+sunx;
    var earthY = 210*sin(-mouseX)+suny;


    stroke(200);
    strokeWeight(1+5*cos(-mouseX));
    line(earthX,earthY,sunx,suny);

    ellipse(earthX ,earthY, 50, 50);

    
    //the sun 

    fill(100+mouseX/3,mouseY/2,20);

    ellipse(sunx,suny,sunw,sunh);

  

    //self orbiting moon 
   

    t = t+(mouseY+mouseX)/80; // change the orbiting speed with the mouse movement 

    stroke(150)
    strokeWeight(1+3*sin(2*mouseX));
    noFill();
    ellipse(earthX,earthY,100,100)

    fill(100+mouseX/2,80+mouseX/4,40);




    ellipse(50*cos(t)+earthX ,50*sin(t)+earthY, 15, 15);



}




  













   


    







dnam-project-03-dynamic-drawing

dnam-Project-03-Dynamic-Drawing

// Doo Won Nam
// 15-104 :: 1 Section B
// dnam@andrew.cmu.edu
// Project-03-Dynamic-Drawing

//basic start - setting the canvas and setting a frame rate to avoid
//too many flickers
//setting the variables for Height so it can change
var rectHeight = 20;
//setting the variable angle to rotate the rectangle
var angle = 0;

function setup() {
  createCanvas(640, 480);
}
//start with a background that changes color based on the position of the mouse
function draw() {
  background(mouseX - 50, mouseY - 20, mouseX + 100);
//making flowers (left and right) that also change color based on the
//position of the mouse, left changes depending on how the mouse is located
//and right one changes depending on left/right movement of the mouse
//the mouse movement gives the two flowers contrary shades
//I make sure to reset the translate at the end of each 'set'
  push();
  translate(120, 200);
  fill(mouseY, mouseY, mouseY);
  noStroke();
  for (var i = 0; i < 10; i ++) {
    ellipse(0, 30, 40, 100);
    rotate(PI/5);
  }
  pop();
  push();
  translate(500, 200);
  fill(mouseX, mouseX, mouseX);
  noStroke();
  for (var i = 0; i < 10; i ++) {
    ellipse(0, 30, 40, 100);
    rotate(PI/5);
  }
  pop();
//making a rectangle between two flowers that change colors when the
//the mouse is right on top of the rectangle
  if ((mouseX > 210) & (mouseX < 410) &&
        (mouseY > 300) && (mouseY < 300 + rectHeight)) {
        fill(0);
    } else {
        fill(100, 200, 400, 60);
    }

  noStroke();
  rect(210, 300, 200, rectHeight);
//if mouse is on the left, the rectangle increases towards an upward direction
//if mouse is on the right, the rectangle gets bigger in height downwards
//using a boolean and the middle of the canvas (for X), I am able to
//increase the size depending on the position of the mouse
  if (mouseX > 320) {
    rectHeight += 20;  }
  else {
    rectHeight -= 20;
  }
//these two ifs are to ensure the rectangle resets instead of going way below
//or above the canvas size
  if (rectHeight > 480) {
    rectHeight = 0;
  }
  if (rectHeight < -480) {
    rectHeight = 0;
  }
//rectangle that does not fully follow the movement of the mouse, but slowly
//rotate around the mouse. Moving the mouse will affect it's angle, speed, and
//position.
  push();
  translate(mouseX, mouseY);
  rectMode(CENTER);
  rotate(radians(angle));
  rect(mouseX, mouseY, 20, 20);
  pop();
  angle = angle + .1;
//speeds up / changes angle when mouse is over 200 in the x axis.
  if (mouseX > 200) {
    angle = angle + 1;
  }
}

Making an interactive, dynamic drawing was very difficult for me. One of the aspects that I struggled with the most would be making sure the artwork would change as my mouse moves. I was not sure what to draw with the program, so I decided to create something that resembles a face (as we made faces the last two projects, making a face felt natural). By following the guidelines, I used bright colours to decorate the piece.

ctv-project-02

sketch

//Ty Van de Zande
//Section B
//ctv@andrew.cmu.edu
//Assignment-03-A

var wid = 640;
var hgt = 480;
var colo = 0;

function setup() {
    createCanvas(wid, hgt);
}
 
function draw() {
    //rota variable must be defined 
    //in the draw loop, so it updates every frame
    var rota = mouseX/200;
    background(170, 190, 200);
    fill(colo);
    
    //starts a shape to apply features (eye)
    push(); 
    translate(width/3, height/3); //place on canvas
    rotate(rota);
    rect(-26, -26, 52, 52); //square
    rect(0, -26, 52, 52); //makes it a rectangle
    pop(); // ends shape features
    
    //starts a shape to apply features (eye)
    push(); 
    translate(width/3*2, height/3);
    rotate(rota);
    rect(-26, -26, 52, 52);
    rect(0, -26, 52, 52);
    pop();
    
    //starts a shape to apply features (mouth)
    push(); 
    translate(width/2, height/3*2);
    //changes openness of mouth based on mouseY
    arc(0, 50, 90, mouseY, 0, PI, OPEN);
    pop(); 
    
    //starts nose with features
    push();
    translate(mouseX, mouseY);
    //draws nose
    beginShape();
    curveVertex(0, 0);
    curveVertex(10, 10);
    curveVertex(40, 40);
    curveVertex(80, 80);
    curveVertex(100, 120);
    curveVertex(80, 140);
    curveVertex(40, 130);
    curveVertex(10, 100);
    curveVertex(0, 0);
    
    // change direction of nose, based on cursor
    if (mouseX <= width/2) { 
        scale(-.75, .75);

    } else { //scales down nose shape
        scale(.75,.75);
    }
    endShape(); 
    pop();
}

//if you click, it changes black to white!
function mousePressed(){
    if(colo == 0){
        colo = 255;
    noStroke();
    } else {
        colo = 0;
    }
}

 

This project was fun because it was cool to play with the shapes while programming each line. I wish I had spent more time on it, but I spent wayyyy too much time trying to figure out coordinates for the nose. The nose still looks horrible, so I just need to spend more time using curveVertex() for drawing.

project3-keuchuka

project 3

//Fon Euchukanonchai
//15-105 SECTION A
//keuchuka@andrew.cmu.edu
//Project-03

//variables for face
var eyeX = 314;
var righteyeY = 132;
var lefteyeY = 305;
var eyeWidth = 100;

var smileAngle1 = -50;
var smileAngle2 = smileAngle1 - 260;

//variables for bankground
var leftrectX = 128;
var rightrectX = 384;
var rectY = 0;
var rectWidth = 148;
var rectHeight = 480;



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

// constraining eye width, right eye and left eye Y and X axis positions, 

	var eyeWidth = constrain(mouseX/100, 20, 150);
	var conrighteyeY = constrain(righteyeY, 190, 220);
	var conlefteyeY = constrain(lefteyeY, 280, 300);
	var coneyeX = constrain(eyeX, 40, 600);
	var conmouseX = constrain(mouseX, 40, 450);

// base yellow background

	background(255, 233, 141);


// when mouse moves past first recteangle to the right, the eyes increase in size and the
// distance between them increases, but is constrained to not fall of the canvas

 	if (mouseX>256) {
 		eyeWidth = eyeWidth + mouseX/10;
 		righteyeY = conrighteyeY - mouseX/300;
 		lefteyeY = conlefteyeY + mouseX/300;
 		lefteyeY = conlefteyeY - mouseX/200;
 	}
 		
 // configures the smile arc angle runs freely wehn mouse is moving in between the two ends
 	if (256<mouseX<600) {
 		smileAngle1 = mouseX;

 	}

// fixes larger smile arc angle when mouse is on the right

 	if (mouseX>600) {
 		smileAngle1 = -50;
 	}
 	
 // fixes smaller smile arc angle when mouse is on the left

 	if (mouseX<130) {
 		smileAngle1 = 165;
 		smileAngle2 = 195;
 	}

 // when mouse moves past the rectangle to the left

 	if (mouseX<256) {
 		eyeWidth = eyeWidth - mouseX/100;
  		righteyeY = conrighteyeY + mouseX/200;
 		lefteyeY = conlefteyeY - mouseX/200;

 	}


// variables to change colors on face and rectangle
	
 	R=(480-mouseX)/3;
	G=(mouseY)/3;
	B=mouseY*(100,255);


//eye graphic configurations
	strokeWeight(10);
	stroke(R, G, B, 150);
	fill(R, G, B, 150); 

//left eye
 	ellipse(eyeX, lefteyeY, eyeWidth/2, eyeWidth/2);

//right eye
 	ellipse(eyeX, righteyeY, eyeWidth/2, eyeWidth/2);

//mouth graphic configurations
	angleMode(DEGREES)
	noFill();
	strokeWeight(25);

//mouth
	stroke(R, G, B, 150);
	arc(330, 240, 480, 480, smileAngle1, smileAngle2);

//rectangle graphic configurations
	strokeWeight(25);
	stroke(R, B, G, 100);
	fill(B, R, G, 150);

//rectangles
	rect(leftrectX, rectY, rectWidth, rectHeight);
	rect(rightrectX, rectY, rectWidth, rectHeight);

//eyes move 
 	eyeX = conmouseX;
 	smileAngle2 = smileAngle1 - 260;


}

I wanted to create an understandable narrative using primitive shapes, which led to me to using the arc command. With the set idea of turning a frown upside down, I then proceeded to vary different variables within the face itself as well as the background.

katieche – looking outwards 03



Ever since I was young, I had an interest in fashion, so when I saw Iris Van Herpen’s 3D generative work, I was very intrigued. Unfortunately her website only showcased examples and videos of her work and not how the work was made, so I had to search for other articles. Some of her pieces are hand molded, however, a lot are also 3D printed work as she collaborated with Stratasys’ unique Objet Connex multi-material 3D printing technology. They aim to use generative art to create non-traditional pieces that “animate the body in an organic way,” (dezeen) utilizing computational methods. Although I was unable to find what exact programs or languages she uses to generate her pieces, I did find that for her Magnetic Motion SS 2014 Paris Fashion Week show she collaborated with Canadian architect Philip Beesley and used a combination of advanced computation, synthetic biology, and mechatronics engineering to create the line.

her work
article about her collaboration with Stratasys

dnoh-sectionD-project3-dynamicdrawing

sketch

// red = 205, 63, 63
// green = 63, 205, 63

var liney = 20;
var redX = -15;
var redX2 = 655;
var blueY = -15;
var blueY2 = 495;
var lineT = 0;
var lineB = 480;
var lineL = 0;
var lineR = 640;
var whiteFill = 255;
var lineStrokeR = 63;
var lineStrokeG = 205;
var lineStrokeB = 63;

function setup() {
  createCanvas(640,480);
  background(39,48,47);
}

function draw() {
  background(39,48,47);
//refreshing background

//blinking effect in background
  stroke(39,64,47);
  line(0,liney,width,liney);
  line(0,liney+40,width,liney+40);
  line(0,liney+80,width,liney+80);
  line(0,liney+120,width,liney+120);
  line(0,liney+160,width,liney+160);
  line(0,liney+200,width,liney+200);
  line(0,liney+240,width,liney+240);
  line(0,liney+280,width,liney+280);
  line(0,liney+320,width,liney+320);
  line(0,liney+360,width,liney+360);
  line(0,liney+400,width,liney+400);
  line(0,liney+440,width,liney+440);
  line(0,liney+480,width,liney+480);
  line(0,liney+520,width,liney+520);
  line(0,liney+560,width,liney+560);
  line(0,liney+600,width,liney+600);
  line(0,liney+640,width,liney+640);
  liney = liney + 80;

  if (liney > height) {
    liney = 0;
  }
//reset green lines to make it blink

//color blocks that shoot out
  noStroke();
  rectMode(CENTER);
  fill(0,255,255); //c
  rect(redX,mouseY,20,20);
  redX = redX - 25;
  fill(255,0,255); //m
  rect(redX2,mouseY,20,20);
  redX2 = redX2 + 25;
  fill(255,255,0); //y
  rect(mouseX,blueY,20,20);
  blueY = blueY - 25;
  fill(0); //k
  rect(mouseX,blueY2,20,20);
  blueY2 = blueY2 + 25;

//green crooshair
  stroke(lineStrokeR,lineStrokeG,lineStrokeB);
  strokeWeight(2);
  line(mouseX,lineB,mouseX,lineT);
  line(lineL,mouseY,lineR,mouseY);

  var rectX = 20;
//white box in crosshair
  fill(whiteFill);
  rect(mouseX,mouseY,rectX,rectX);

//white box enlarges when pressed, white box becomes gray, green becomes red
  if (mouseIsPressed) {
    lineM1 = mouseX-50;
    lineV1 = mouseY-50;
    lineM2 = mouseX+50;
    lineV2 = mouseY+50;
    lineM3 = mouseX+50;
    lineV3 = mouseY-50;
    lineM4 = mouseX-50;
    lineV4 = mouseY+50;
    line(lineM1,lineV1,lineM2,lineV2);
    line(lineM3,lineV3,lineM4,lineV4);

    ellipse(mouseX,mouseY,70,70);
    lineStrokeR = 255;
    lineStrokeG = 63;
    lineStrokeB = 63;
    whiteFill = 80;
  } else {
    whiteFill = 255;
    lineStrokeR = 63;
    lineStrokeG = 205;
    lineStrokeB = 63;
  }
  print(mouseIsPressed);
}



function mouseClicked() { //when mouse is clicked, the color squares jump to mouse and start moving again
  redX = mouseX;
  redX2 = mouseX;
  blueY = mouseY;
  blueY2 = mouseY;
}

The background lines are constantly blinking to add an effect of constant movement. The mouse is followed by a vertical and horizontal line that changes colors from green to red when clicked. When clicked, the square in the center changes colors and shapes. Finally, four color blocks jump out of the crosshair when clicked.

Initially I wanted to create a code that would print a square wherever I clicked and the four blocks would collide into that square. However, I could not figure out a code that would let me keep the square after I clicked it.

dchikows – Section C – Category Project – 02 – Variable-Face

sketch

// David Chikowski
// Section C
// dchikows@andrew.cmu.edu
// Project-02



var eyeSize = 12;
var backFinTopX = 541;
var backFinTopY = 162;
var backFinBottomX = 540;
var backFinBottomY = 322;
var mouthOpenTopY = 234;
var mouthOpenBottomY = 245;



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

function draw() {
    background(130,163,196);

    noStroke();
    fill(191,94,71);
    ellipse(279,238,359,131);
    //Main body

    noStroke();
    fill(191,94,71);
    quad(80,231,139,202,136,277,81,248);
    //mouth

    noStroke();
    fill(130,163,196);
    triangle(79,mouthOpenTopY,80,mouthOpenBottomY,103,242);
    //mouth opening

    noStroke();
    fill(56,54,8);
    ellipse(137,232,eyeSize,eyeSize);

    noStroke();
    fill(191,94,71);
    triangle(240,145,205,182,336,188);
    //top fin

    noStroke();
    fill(191,94,71);
    triangle(backFinTopX, backFinTopY, 403, 242, backFinBottomX, backFinBottomY);
    //Back fin


}


function mousePressed() {
    // when the user clicks, these variables are reassigned
    // to random values within specified ranges. For example,
    // 'eyeSize' gets a random value between 12 and 22.

    eyeSize = random(12,22);
    backFinTopX = random(525, 541);
    backFinTopY = random(145, 162);
    backFinBottomX = random(515, 540);
    backFinBottomY = random(295, 322);
    mouthOpenTopY = random(234,246);
    mouthOpenBottomY = random(235,245);



}











I initially approached the project by trying to make an interactive robot, but my process took a turn when I realized I am not very good at coding yet. So I decided to make a fish instead, but it is okay I really enjoy fishing.

katieche – project 03 – dynamic drawing

katieche-03

// alters:
// dot position
// line length
// line and dot color
// speed that dots follow cursor
// angle of lines

// dot 1
var x = 300;
var y = 300;
var diffx = 0;
var diffy = 0;

// dot 5
var a = 320;
var b = 240;
var diffa = 0;
var diffb = 0;

// dot 3
var c = 320;
var d = 240;
var diffc = 0;
var diffd = 0;

// dot 4
var e = 320;
var f = 320;
var diffe = 0;
var difff = 0;

// dot 2
var g = 270;
var h = 220;
var diffg = 0;
var diffh = 0;

function setup() {
    createCanvas(640, 480);
    background(220);
}

function draw() {
	background(0);
    
    stroke(500-mouseX);
    // lines that follow cursor
    // line 1
    line(320, 240, mouseX, mouseY);
    // line 2
    var mx = map(mouseX, 0, width, mouseX, mouseY);
    line(320, 240, mx, mouseY);
    // line 3
    var mx = map(mouseX, 0, width, mouseX, mouseY);
    line(320, 240, mx, mouseY);
    // line 4
    var mx = map(mouseX, 0, width, mouseX, mouseY);
    line(320, 240, mx, mouseY);
    // line 5
    var mx = map(mouseX, 100, width,mouseX, mouseY);
    line(320, 240, mx, mouseY);

    // longer lines
    stroke(320-mouseX);
    // line 1
    var mx = map(200, mouseY, width, -260, 380);
    line(320, 240, mx, mouseY);
    // line 2
    var mx = map(-mouseX, 40, width, 760, -180);
    line(320, 240, mx, mouseY);
    // line 3
    var mx = map(mouseX, 30, width, -260, 100);
    line(320, 240, mx, mouseY);
    // line 4
    var mx = map(-mouseX, 300, width, 660, 190);
    line(320, 240, mx, mouseY);

    // dot 1 (slow)
    // dots are in order: slow to fast
    noStroke();
	diffx = mouseX - x;
    diffy = mouseY - y;
    x = x + 0.01*diffx;
    y = y + 0.01*diffy;
    fill (250-mouseY);
    ellipse(x, y, 10, 10);

    // dot 2
    diffg = mouseX - g;
    diffh = mouseY - h;
    g += 0.03*diffg;
    h += 0.03*diffh;
    fill (240-mouseX);
    ellipse(g, h, 35, 35);

    // dot 3
    diffc = mouseX - c;
    diffd = mouseY - d;
    c = c + 0.05*diffc;
    d = d + 0.05*diffd;
    fill (240-mouseX);
    ellipse(c, d, 30, 30);

  	// dot 4
    diffe = mouseX - e;
    difff = mouseY - f;
    e += 0.07*diffe;
    f += 0.07*difff;
    fill (300-mouseY);
    ellipse(e, f, 25, 25);

   	// dot 5 (fastest)
    diffa = mouseX - a;
    diffb = mouseY - b;
    a = a + 0.1*diffa;
    b = b + 0.1*diffb;
    fill (500-mouseX);
    ellipse(a, b, 20, 20);

}

This project was hard for me since it was so open ended, I didn’t know where to start or where to go, so I referenced the notes a lot. I knew I wanted to do something abstract, so I started with a few interactive functions that I thought were cool (ie. the dots following the cursor, and the lines changing based on the mouse position), and then played around with the code from there. Here are a few things I first tried:

I wanted to combine some of these functions but the circles and the lines just looked too crowded together so I switched to the dots that follow the cursor, so it seems like the lines follow the dots.

svitoora – 03 Dynamic Gravity Drawings

Gravity

//
// Supawat Vitoorapakorn
// Svitoora@andrew.cmu.edu
// Section E
//
// Gravity is a point mass dynamic drawing inspired
// from physics, nature, and falling off a skateboard.
// f = G (m1*m2)/d^2
// f = G sum(m)/(d from avg)^2


// World Model Setup /////////////////////////////////////
var w = 480;
var h = 640;
var t = 1; // time variable
var g = .0025; // gravity
var count = 0; // global count of objects

var ball;
var balls = []; // Array of objects
var ball_size = w * .010 // Default object size

var max_count = 30;
var auto_every = 35;
var max_line = 1000; // Prevents crash


// Control ///////////////////////////////////////////////

// Creates new object in system given (x,y)
function ball_create(x, y) {
	this.x = x;
	this.y = y;
	this.vx = 0;
	this.vy = 0;
	this.r = ball_size;
	this.m = 1;
	this.alpha = 255
}

// Add new object and delete oldest object
function mouseDragged() {
	if (t % 10) {
		balls.push(new ball_create(mouseX, mouseY));
	}
	if (balls.length >= max_count) {
		balls.splice(0, 1)
	}
}

// Add new object and delete oldest object
function mousePressed() {
	balls.push(new ball_create(mouseX, mouseY));
	if (balls.length >= max_count) {
		balls.splice(0, 1)
	}
}


// World /////////////////////////////////////////////////

// Maintain global count of balls
function count_balls(balls) {
	count = balls.length;
}

// Maintain global mass of system
function sum_mass(balls) {
	sum_m = 0;
	for (i in balls) {
		sum_m += balls[i].m;
	}
	return sum_m;
}

// Determines the system's average position X
function average_posX(balls) {
	if (balls.length == 0) {
		return w / 2;
	};
	var sum_x = 0;
	for (i in balls) {
		sum_x += balls[i].x;
	}
	avg = sum_x / balls.length
	return avg;
}

// Determines the system's average position Y
function average_posY(balls) {
	if (balls.length == 0) {
		return h / 2;
	};
	var sum_y = 0;
	for (i in balls) {
		sum_y += balls[i].y;
	}
	avg = sum_y / balls.length;
	return avg
}

// Apply gravity for all objects in the system
function gravity(balls) {
	var avg_x = average_posX(balls);
	var avg_y = average_posY(balls);
	var speed = .1 //0-1 Multuplier for controlling velocity of attratction
	for (i in balls) {
		d = dist(balls[i].x, balls[i].y, avg_x, avg_y);
        ds = map(d,0,w/2,1,0);  // used to simulate d^2
		
        // Gravity X
        if (balls[i].x > avg_x) {
			balls[i].x *= 1 - (g * (count * speed));
		} else { balls[i].x *= 1 + (g * (count * speed+ds));}

        // Gravity Y
		if (balls[i].y > avg_y) {
			balls[i].y *= 1 - (g * (count * speed))
		} else { balls[i].y *= 1 + (g * (count * speed+ds));}
	}
}

// Add object to system in the middle; // Used at setup()
function add_ball(balls) {
	balls.push(new ball_create(w / 2, h / 2));
}

// Prevents software from crashing
// from too many objects beyond max_count
function death(balls, t) {
	if (balls.length >= max_count) {
		balls.splice(0, 1);
		for (i in balls) {
			balls[i].r *= .99;
		}
	}
}

// Connects all the object in the system via a line
function draw_line(balls) {
	lines = 0
	alpha = 255 * .2

	if (lines < max_line) {
		for (i in balls) {
			var x_1 = balls[i].x;
			var y_1 = balls[i].y;
			for (i in balls) {
				var x_2 = balls[i].x;
				var y_2 = balls[i].y;
				stroke(255, 255, 255, alpha);
				line(x_1, y_1, x_2, y_2);
				lines += 1;
			}
		}
	}
}

// SETUP
function setup() {
	createCanvas(w, h);
	g = .0025;
	background(50);
	balls.length = 0; // Kill all objects in system
	add_ball(balls);
}

// Refreshes the systems with new objects
// Removes old objects and add new objects
function auto_refresh(balls, t) {
	// Starts refreshing system at 5 objects
	// every auto_every interval.
	if (t % auto_every == 0 & balls.length > 5) {
		balls.splice(0, 1);
	}
	X = constrain(mouseX, 1, w);
	Y = constrain(mouseY, 1, h)
	if (t % auto_every == 0) {
		balls.push(new ball_create(X, Y));
	}

	// Resets the system to 8 objects once every 500 ms
	// This prevents overload; Array starts at [0]
	if (t % 500 == 0 & balls.length > 8) {
		balls.length = 7;
	}
}

// Draw ////////////////////////////////////////////////////

// Draw all objects in systems mapped by distance from avg
function draw_balls(balls) {
	for (ball in balls) {
		noStroke();
		var avg_x = average_posX(balls);
		var avg_y = average_posY(balls);
		var d = dist(balls[ball].x, balls[ball].y, avg_x, avg_y);

		// Size and Alpha of Ball is a function of distance
		var alpha = map(d, balls[ball].r, w / 2, 255, 0);
		var size = map(d, 0, w / 2, .5, -1.5) //max to min

		fill(255, 255, 255, alpha);
		ellipse(balls[ball].x, balls[ball].y,
			balls[ball].r * (2 + size),
			balls[ball].r * (2 + size));
	}
}


// Execute /////////////////////////////////////////////////
function draw() {
	background(50);
	noStroke();
	// Update World
	t = t + 1;
	count_balls(balls);
	auto_refresh(balls, t);
	if (balls.length > 1) {
		gravity(balls);
	}
	death(balls, t);

	// Draw World
	draw_line(balls);
	draw_balls(balls);
}

Physics

 Gravity is a point mass dynamic drawing inspired from physics, nature, and falling off a skateboard. I wanted to create a systematic representation of mass attracts mass. To do this I was inspired by the physics formula:

Image result for f = m1m2

The problem with this forumla is that it is meant for physicist dealing with a two body system. In my case, I wanted a forumla that worked with multiple bodies in a system algorithmically. After sketching for a while with equations on the white board, I realized that that the problem I was trying to solve was much simplier than I expected.

Trying to figure out the algorithm behind multiple bodied system gravity.

Essentially the problem boils down to averages. If all the object in the system had a mass of 1, then the center of mass of the system would be at the average coordinate position of every point mass. By definition this is the centroid of the system.

Related image
Center of gravity is by definition the centroid of a multiple body system.

After defininig the centroid, I simply make every object in the system moves towards it. To replicate d^2’s effect on speed, I use a position *= and /= function, in addition to a mapping function of speed based off distance away from the centroid.

Model-View-Controller  (MVC)

This programs uses the MVC framework taught in 15-112. Objects are models are added to an array, modfified by the controller, and then representated through view functions. Because of the complexity of this code, I used to object-oriented programming to organize my variables. I didn’t quite understand object-based methods in javascript yet, so I worked around them.

Demo and Project Requirments:

Press and hold.

To sastify the project requirement, there are no random or non-deterministic element. Every function is deterministic, therefore given the exact same mouse input the Gravity will create the exact same drawing. The variables that are being altered in how the image is being created are: size, position, opacity, angle, etc.

Stills from Gravity: Slow vs Fast Drawing

SaveSave

SaveSave

SaveSave