Project 11

screen-shot-2016-11-11-at-11-41-42-pmscreen-shot-2016-11-11-at-11-41-50-pm

I really enjoyed this project.  I liked being able to add in the color changing functions because it added variety and made the turtle design a bit more engaging. sketch

var turtle;
var startFrame;

var r = 235;
var g = 200;
var b = 200;
var x = 300;
var y = 300;

function setup() {
    createCanvas(600, 600);
    background(0);
    x = mouseX;
    y = mouseY;
    turtle = makeTurtle(430,100);
    turtle.setColor(color(r,g,b));
    stroke(r,g,b);
    fill(r,g,b);
    turtle.setWeight(1); 
    turtle.penDown();
    frameRate(10);
}

function draw(){

    for (var i = 0; i < 100; i++) {
        if(i %2){
        r = r - random(0,.08);
        g = g - random(.03,.06);
        b = b - random(.01,.2);
    }
        turtle.setColor(color(r,g,b));
        turtle.forward(90);
        turtle.right(80.5);
        turtle.forward(60);
        if (i % 50 === 0) {
            turtle.forward(200);
        }
    }         
}

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

function turtleLeft(d){this.angle-=d;}function turtleRight(d){this.angle+=d;}
function turtleForward(p){var rad=radians(this.angle);var newx=this.x+cos(rad)*p;
var newy=this.y+sin(rad)*p;this.goto(newx,newy);}function turtleBack(p){
this.forward(-p);}function turtlePenDown(){this.penIsDown=true;}
function turtlePenUp(){this.penIsDown = false;}function turtleGoTo(x,y){
if(this.penIsDown){stroke(this.color);strokeWeight(this.weight);
line(this.x,this.y,x,y);}this.x = x;this.y = y;}function turtleDistTo(x,y){
return sqrt(sq(this.x-x)+sq(this.y-y));}function turtleAngleTo(x,y){
var absAngle=degrees(atan2(y-this.y,x-this.x));
var angle=((absAngle-this.angle)+360)%360.0;return angle;}
function turtleTurnToward(x,y,d){var angle = this.angleTo(x,y);if(angle< 180){
this.angle+=d;}else{this.angle-=d;}}function turtleSetColor(c){this.color=c;}
function turtleSetWeight(w){this.weight=w;}function turtleFace(angle){
this.angle = angle;}function makeTurtle(tx,ty){var turtle={x:tx,y:ty,
angle:0.0,penIsDown:true,color:color(128),weight:1,left:turtleLeft,
right:turtleRight,forward:turtleForward, back:turtleBack,penDown:turtlePenDown,
penUp:turtlePenUp,goto:turtleGoTo, angleto:turtleAngleTo,
turnToward:turtleTurnToward,distanceTo:turtleDistTo, angleTo:turtleAngleTo,
setColor:turtleSetColor, setWeight:turtleSetWeight,face:turtleFace};
return turtle;}

mreyes-project-11-turtle drawing tool

sketch

//Mercedes Reys

//Section C 

//mreyes@andrew.cmu.edu

//project-11

//trutle varaibles 
var t1;
var t2;
var t3;
var t4;
function setup() {

    createCanvas(800, 800);
    background('pink');
    //turtles 
    t1 = makeTurtle(width / 2 , height / 2);
    t2 = makeTurtle(width / 2 , height / 2);
    t3 = makeTurtle(width / 2 , height / 2);
    t4 = makeTurtle(width / 2 , height / 2);
  
}
 
function draw() {
//turtles move forward twards target 
    t1.forward(1);
    t2.forward(1);
    t3.forward(1);
    t4.forward(1);
// target is mouse location
    var targetX = mouseX;
    var targetY = mouseY;
    strokeWeight(1);
    stroke(128);
// turtles move tward target but at varying amounts 
    t1.turnToward(targetX, targetY,1);
    t2.turnToward(targetX, targetY,2);
    t3.turnToward(targetX, targetY,3);
    t4.turnToward(targetX, targetY,4);


}


function turtleLeft(d){this.angle-=d;}function turtleRight(d){this.angle+=d;}
function turtleForward(p){var rad=radians(this.angle);var newx=this.x+cos(rad)*p;
var newy=this.y+sin(rad)*p;this.goto(newx,newy);}function turtleBack(p){
this.forward(-p);}function turtlePenDown(){this.penIsDown=true;}
function turtlePenUp(){this.penIsDown = false;}function turtleGoTo(x,y){
if(this.penIsDown){stroke(this.color);strokeWeight(this.weight);
line(this.x,this.y,x,y);}this.x = x;this.y = y;}function turtleDistTo(x,y){
return sqrt(sq(this.x-x)+sq(this.y-y));}function turtleAngleTo(x,y){
var absAngle=degrees(atan2(y-this.y,x-this.x));
var angle=((absAngle-this.angle)+360)%360.0;return angle;}
function turtleTurnToward(x,y,d){var angle = this.angleTo(x,y);if(angle< 180){
this.angle+=d;}else{this.angle-=d;}}function turtleSetColor(c){this.color=c;}
function turtleSetWeight(w){this.weight=w;}function turtleFace(angle){
this.angle = angle;}function makeTurtle(tx,ty){var turtle={x:tx,y:ty,
angle:0.0,penIsDown:true,color:color(128),weight:1,left:turtleLeft,
right:turtleRight,forward:turtleForward, back:turtleBack,penDown:turtlePenDown,
penUp:turtlePenUp,goto:turtleGoTo, angleto:turtleAngleTo,
turnToward:turtleTurnToward,distanceTo:turtleDistTo, angleTo:turtleAngleTo,
setColor:turtleSetColor, setWeight:turtleSetWeight,face:turtleFace};
return turtle;}

I wanted to make a little interactive turtle sketch that would draw follow your mouse and draw varying compositions. The code is simple, but I think the program is fairly intuitive and entertaining. Depending on how you move your mouse around and how long you play with it the composition can get messy, but overall it generates fairly pleasing designs.

screen-shot-2016-11-11-at-11-33-26-pmscreen-shot-2016-11-11-at-11-38-59-pmscreen-shot-2016-11-11-at-11-39-30-pm

Looking Outwards 11

I really liked Sony’s Evans-bot. An animated robot that creates songs, it is given a series of constraints for melody and harmony, a primary chord to work off of, and then a few backup chords. These constraints are called on a “leadsheet,” described by the creator as “monophonic melodies with underlying chord sequence, “in the style ” of arbitrary composers, or corpora.”

I really like this project especially because the music is programmed to sound like a particular style of a composer like George Gershwin or Irving Berlin. I’m a big Gershwin and Berlin fan so I enjoyed hearing trademarks of their music within the program. I’m not sure how a computer would’ve been programmed to create such a thing, but I highly enjoyed it and trying to reason through a potential code.

Link to Work

 

sihand – Project Week 11 – Free Turtle

sketch-sihan

//Sihan Dong
//sihand@andrew.cmu.edu
//Section B
//Week 11: Project turtle

var gravity = 0.3;   // downward acceleration
var springy = 0.7; // how much velocity is retained after bounce
var drag = 0.0001;    // drag causes particles to slow down
var np = 50;      // how many particles
var turtleColor = [];

function particleStep() {
    this.age++;
    this.x += this.dx;
    this.y += this.dy;
    stroke(this.dr, this.dg, this.db);
    strokeWeight(this.dw);
  
    if (this.x > width) { // bounce off right wall
        this.x = width - (this.x - width);
        this.dx = -this.dx * springy;
    } else if (this.x < 0) { // bounce off left wall
        this.x = -this.x;
        this.dx = -this.dx * springy;
    }
    if (this.y > height) { // bounce off bottom
        this.y = height - (this.y - height);
        this.dy = -this.dy * springy;
    } else if (this.y < 80) { // bounce off top
        this.y = 80 - (this.y - 80);//-this.y;
        this.dy = -this.dy * springy;
    }
    this.dy = this.dy + gravity; // force of gravity
    // drag is proportional to velocity squared
    // which is the sum of the squares of dy and dy
    var vs = Math.pow(this.dx, 2) + Math.pow(this.dy, 2);
    // d is the ratio of old velocty to new velocity
    var d = vs * drag;
    // d goes up with velocity squared but can never be
    // so high that the velocity reverses, so limit d to 1
    d = min(d, 1);
    // scale dx and dy to include drag effect
    this.dx *= (1 - d);
    this.dy *= (1 - d);

}

function particleDraw() {
    point(this.x, this.y);
}


// create a "Particle" object with position and velocity
function makeParticle(px, py, pdx, pdy, pr, pg, pb, pw) {
    p = {x: px, y: py,
         dx: pdx, dy: pdy, 
         dr: pr, dg: pg, db: pb,
         dw: pw,
         age: 0,
         step: particleStep,
         draw: particleDraw
        }
    return p;
}

var particles = [];


function setup() {
    createCanvas(500, 500);
    frameRate(8);
    turtleSlope = new makeTurtle(0, 0);

}


function draw() {
  background(184, 197, 245);

  //draw the chains
	for (i = 0; i < 25; i++) {
    turtleSlope.penUp();
    turtleSlope.right(30);
    turtleSlope.setColor(255);
    tSlope(20*i, 70); //1
    turtleSlope.setColor(0);
    tSlope(width/2, height/2-20); //2
    turtleColor[i] = color(random(100, 255), random(100, 255), random(100, 255));
    turtleSlope.setColor(turtleColor[i]);
    tSlope(100*i, 370); //3
    fill(0); 
	}

    if (mouseIsPressed) {
        var newp = makeParticle(mouseX, mouseY,
                                random(-10, 10), random(-10, 0), 
                                255, 255, 255,
                                random(10, 30));
        particles.push(newp);
    }

    newParticles = [];
    for (var i = 0; i < particles.length; i++) { // for each particle
        var p = particles[i];
        p.step();
        p.draw();
        if (p.age < 200) {
            newParticles.push(p);
        }
    }
    
    particles = newParticles;

}

function tSlope(lx, ly){
	turtleSlope.goto(lx, ly);
  turtleSlope.setWeight(4);
  turtleSlope.right(90);
  turtleSlope.forward(random(7));//the amount of fluctuation
  
  turtleSlope.penDown();
  turtleSlope.left(60);
  turtleSlope.forward(10);
  turtleSlope.right(60);
  turtleSlope.forward(10);
  turtleSlope.right(30);
  turtleSlope.forward(17.3);
  turtleSlope.right(120);
  turtleSlope.forward(17.3);
  turtleSlope.right(30);
  turtleSlope.forward(10);
  turtleSlope.right(60);
  turtleSlope.forward(10);
  turtleSlope.right(30);
	turtleSlope.penUp();

}

//========== TURTLE GRAPHICS ===============//
function turtleLeft(d) {
    this.angle -= d;
}
 
 
function turtleRight(d) {
    this.angle += d;
}
 
 
function turtleForward(p) {
    var rad = radians(this.angle);
    var newx = this.x + cos(rad) * p;
    var newy = this.y + sin(rad) * p;
    this.goto(newx, newy);
}
 
 
function turtleBack(p) {
    this.forward(-p);
}
 
 
function turtlePenDown() {
    this.penIsDown = true;
}
 
 
function turtlePenUp() {
    this.penIsDown = false;
}
 
 
function turtleGoTo(x, y) {
    if (this.penIsDown) {
      stroke(this.color);
      strokeWeight(this.weight);
      line(this.x, this.y, x, y);
    }
    this.x = x;
    this.y = y;
}
 
function turtleSetColor(c) {
    this.color = c;
}
 
function turtleSetWeight(w) {
    this.weight = w;
}
 
function makeTurtle(tx, ty) {
    var turtle = {x: tx, y: ty,
                  angle: 0.0, 
                  penIsDown: true,
                  color: color(128),
                  weight: 1,
                  left: turtleLeft, right: turtleRight,
                  forward: turtleForward, back: turtleBack,
                  penDown: turtlePenDown, penUp: turtlePenUp,
                  goto: turtleGoTo, 
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  };
    return turtle;
}

I’ve wanted to experiment with how turtle moves so I did so with this project. The turnout is not exactly ideal and I will continue practicing with turtles.

I also experimented with the particles because I think their movements are fascinating.

GarrettRauck-project-11 (Click to add turtles)

sketch

//Garrett Rauck
//Section C
//grauck@andrew.cmu.edu
//Assignment-07a-Bar Chart

/////////////////////////////////
// INIT VARIABLES
/////////////////////////////////
//canvas vars
var canvasWidth, canvasHeight;

//INPUT IMAGE
//option 1:
//var imgUrl = "http://i.imgur.com/b24JQcX.jpg?1"; // url for the input image
//option 2:
var imgUrl = "http://i.imgur.com/koPvfoe.jpg"; // url for the input image

var img; //the input image object

//2d list of booleans tracking which pixels have been visited
//visited = true; not visited = false
var visitedPixels = [];

//
var turtles = []; //store all turtle instances in list
var newTurtles = []; //store turtles to add on next frame
var deadTurtles = []; //store turtles to remove on next frame
var colorTurtle, colorBackground;

//
var darknessThreshold, brightnessThreshold;
var maxNumberOfTurtles;

/////////////////////////////////
// RUN!
/////////////////////////////////
function preload() {
	img = loadImage(imgUrl);
}

function setup() {
	// INIT VARS
	//set canvas size based on imput image
	canvasWidth = 800;
	canvasHeight = 800;
	//set control variables
	darknessThreshold = 50;
	brightnessThreshold = 70;
	maxNumberOfTurtles = 25;
	//set colors
	colorTurtle = color(255);
	colorBackground = color(0);

	//populate visited pixels list such that it is a 2d list of booleans
	//representing each pixel in the canvas. false means that the pixel
	//has not been visited by turtles yet.
	for (var y = 0; y < canvasHeight; y++) {
		//create list to store row of values
		var row = [];
		//populate row list with all falses for n columns
		for (var x = 0; x < canvasWidth; x++) {
			row.push(false);
		}
		//add row list to 2d visitedPixels array
		visitedPixels.push(row);
	}

	// CANVAS SETUP
    createCanvas(canvasWidth, canvasHeight);
    background(colorBackground);
}

function draw() {
	//if program termination condition hasn't been met...
	if (fin() != true) {
		//for each turtle in list of active turtles...
		for (var i=0; i<turtles.length; i++) {
			//get turtle object
			var turtle = turtles[i];
			//walk
			walkTurtle(turtle);
		}
	}
	//add new turtles to list of all turtles for next generation
	updateTurtlesList();
}

/////////////////////////////////
// HELPER FNS
/////////////////////////////////
function walkTurtle(turtle) {
	//start drawing
	turtle.penDown();
	//move forward 1 pixel
	turtle.forward(1);
	//check if pixel visited already, continue if unvisited
	if (isValidStep(turtle)) {
		var x = int(turtle.x); //sometimes these values become floats...
		var y = int(turtle.y); //so use int() to ensure integer value
		//determine turtle's fate based on pixel brightness:
		var pix = img.get(x,y);

		//if pixel too dark, turtle dies
		if (brightness(pix) > darknessThreshold) {
			// println("Turtle die!");
			killTurtle(turtle);
		}
		//else if pixel bright enough, spawn children turtles at location
		else if (brightness(pix) > brightnessThreshold) {
			println("Spawn!")
			spawnTurtle(x, y, 90); //spawn turtle to left
			spawnTurtle(x, y, -90); //spawn turtle to right
		}
		else {
		}
	}
	//else, if pixel is visited already, erase. Then, respawn elsewhere
	else {
		// println("Respanw!");
		//move backward 1 pixel
		turtle.back(1);
		//respawn somewhere else
		respawnTurtle(turtle);
	}
}

function isValidStep(turtle) {
	//get x and y pixel position of turtle
	var x = int(turtle.x); //sometimes these values become floats...
	var y = int(turtle.y); //so use int() to ensure integer value
	//if turtle off of canvas
	if ((x <= 0) || (x >= canvasWidth) || (y <= 0) || (y >= canvasHeight)) {
		return false;
	}
	//if pixel already visited, step is not valid. return false
	else if (visitedPixels[x][y] == true) {return false;}
	//if pixel not visited, step is valid. return true
	else {
		//update visited pixels
		visitedPixels[x][y] = true;
		return true;
	}
}

function spawnTurtle(x,y,dir) {
	if (turtles.length < maxNumberOfTurtles) {
		//create new turtle instance
		var turtle = makeTurtle(x,y);
		//rotate turtle based on input dir
		turtle.left(dir);
		//set turtle color
		turtle.color = colorTurtle;
		//store turtle in list of turtles to be added to master list
		newTurtles.push(turtle);
	}
}

function respawnTurtle(turtle) {
	//get random x and y pixel coordinates
	var x = int(random(canvasWidth));
	var y = int(random(canvasHeight));
	var theta = 90*(int(random(4)));
	//move turtle to new pixel
	turtle.penUp();
	turtle.goto(x,y);
	turtle.penDown();
	//turn turtle
	turtle.left(theta);
	//if move is to a cell that hasn't been visit, continue
	if (isValidStep(turtle)) {
		//update visited pixels
		visitedPixels[x][y] = true;
		//exit function
		return;
	}
	//if move is to cell that has already been visited, try again
	else {respawnTurtle(turtle);}
}

//function to remove turtle from list of active turtles
function killTurtle(turtle) {
	deadTurtles.push(turtle);
	// //new list to store all active turtles
	// var newTurtlesList = [];
	// //get index of turtle to remove from list of turtles
	// var indexOfTurtleToRemove = turtles.indexOf(turtle);
	// println(indexOfTurtleToRemove ==
	// //loop over list of turtles, build new list, excluding newly dead turtle
	// for (var i=0; i<turtles.length; i++) {
	// 	//if turtle is not the one we are killing, add it to the list
	// 	if (i != indexOfTurtleToRemove) {newTurtlesList.push(turtles[i]);}
	// }
	// //update turtles list
	// turtles = newTurtlesList;
}

//function for adding newly spawned turned to list of active turtles
function updateTurtlesList(){
	var newTurtlesList = [];
	for (var i=0; i<turtles.length; i++) {
		if ((deadTurtles.indexOf(turtles[i])) == -1) {
			newTurtlesList.push(turtles[i]);
		}
	}
	//for each new turtle spawned in past generation...
	for (var j=0; j<newTurtles.length; j++) {
		//add new turtle to list of active turtles
		newTurtlesList.push(newTurtles[j]);
	}
	turtles = newTurtlesList;
}

// function for ending the program if all cells have been visited
function fin() {
	//check if cells have been visited or not
	for (var x=0; x<visitedPixels.length; x++) {
		for (var y=0; y<visitedPixels[0].length; y++) {
			//if any cell is found unvisited, return false to continue program
			if (visitedPixels[x][y] == false) {
				return false;
			}
		}
	}
	//if get through all cells and all have been visited, finish
	return true;
}

/////////////////////////////////
// EVENTS
/////////////////////////////////
function mousePressed() {
	//spawn new turtle at mouse x and y with random N/S/E/W direction
	spawnTurtle(int(mouseX),int(mouseY),90*(int(random(4))));
}

/////////////////////////////////
// TURTLE CLASS
/////////////////////////////////
function turtleLeft(d){this.angle-=d;}function turtleRight(d){this.angle+=d;}
function turtleForward(p){var rad=radians(this.angle);var newx=this.x+cos(rad)*p;
var newy=this.y+sin(rad)*p;this.goto(newx,newy);}function turtleBack(p){
this.forward(-p);}function turtlePenDown(){this.penIsDown=true;}
function turtlePenUp(){this.penIsDown = false;}function turtleGoTo(x,y){
if(this.penIsDown){stroke(this.color);strokeWeight(this.weight);
line(this.x,this.y,x,y);}this.x = x;this.y = y;}function turtleDistTo(x,y){
return sqrt(sq(this.x-x)+sq(this.y-y));}function turtleAngleTo(x,y){
var absAngle=degrees(atan2(y-this.y,x-this.x));
var angle=((absAngle-this.angle)+360)%360.0;return angle;}
function turtleTurnToward(x,y,d){var angle = this.angleTo(x,y);if(angle< 180){
this.angle+=d;}else{this.angle-=d;}}function turtleSetColor(c){this.color=c;}
function turtleSetWeight(w){this.weight=w;}function turtleFace(angle){
this.angle = angle;}function makeTurtle(tx,ty){var turtle={x:tx,y:ty,
angle:0.0,penIsDown:true,color:color(128),weight:1,left:turtleLeft,
right:turtleRight,forward:turtleForward, back:turtleBack,penDown:turtlePenDown,
penUp:turtlePenUp,goto:turtleGoTo, angleto:turtleAngleTo,
turnToward:turtleTurnToward,distanceTo:turtleDistTo, angleTo:turtleAngleTo,
setColor:turtleSetColor, setWeight:turtleSetWeight,face:turtleFace};
return turtle;}

In this sketch, I was trying to have a series of turtles walk about an image and respond based on the brightness of the pixels. The rules I was attempting to employ:

  1. When a turtle reaches a pixel that is brighter than a certain value, spawn two child turtles to the left and to the right.
  2. When a turtle reaches a pixel that is darker than a certain value, that turtle “dies”.
  3. If a turtle reaches a pixel that has already been visited by another turtle, or if the turtle runs off the canvas, that turtle respawns to another random location.

What I was able to achieve creates an interesting composition; however, I don’t think it is reacting to the image as I intended.

ShanWang-Project11-(click on the canvas)

For this project I’m interested in the dynamic shapes that the turtle graphic is able to produced. I selected a spiral base shape and users can click on the canvas to generate the geometry in different sizes.

sketch

//Shan Wang
//Section A
//shanw1@andrew.cmu.edu
//11-Project



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

}

function mousePressed(){
    alpha += 50;
    //randomly select the number of rotates the basic geometry will go
    var numRotate = random(30,60);
    //randomly choose the initial strokeWeight for turtle
    var strokeWei = random(0.2,1);
    //base the size of the graph on the number of rotation
    var size = map(numRotate,30,60,80,200);
    //base the initial gradient of stroke on the position of x
    var color = round(map(mouseX, 0, width, 150,200));

    //create a turtle at the position where the mouse is pressed
    var turtle1 = makeTurtle(mouseX,mouseY,color,strokeWei);

    //set the decrement unit for color and stroke weight
    var intervStro = turtle1.weight/numRotate;
    var intervCol = turtle1.color/numRotate;

    //generate the spiral
    for (var counts = 0; counts < numRotate; counts++){
        turtle1.penDown();
        turtle1.color -= intervCol;
        turtle1.weight -= intervStro;
        //draw square
        for (var j = 0; j<4; j++){
            turtle1.forward(size-counts*2);
            turtle1.right(90);
        }
        turtle1.left(10);
    }
}





function turtleLeft(d) {
    this.angle -= d;
}


function turtleRight(d) {
    this.angle += d;
}


function turtleForward(p) {
    var rad = radians(this.angle);
    var newx = this.x + cos(rad) * p;
    var newy = this.y + sin(rad) * p;
    this.goto(newx, newy);
}


function turtleBack(p) {
    this.forward(-p);
}


function turtlePenDown() {
    this.penIsDown = true;
}


function turtlePenUp() {
    this.penIsDown = false;
}


function turtleGoTo(x, y) {
    if (this.penIsDown) {
      stroke(this.color);
      strokeWeight(this.weight);
      line(this.x, this.y, x, y);
    }
    this.x = x;
    this.y = y;
}


function turtleDistTo(x, y) {
    return sqrt(sq(this.x - x) + sq(this.y - y));
}


function turtleAngleTo(x, y) {
    var absAngle = degrees(atan2(y - this.y, x - this.x));
    var angle = ((absAngle - this.angle) + 360) % 360.0;
    return angle;
}


function turtleTurnToward(x, y, d) {
    var angle = this.angleTo(x, y);
    if (angle < 180) {
        this.angle += d;
    } else {
        this.angle -= d;
    }
}


function turtleSetColor(c) {
    this.color = c;
}


function turtleSetWeight(w) {
    this.weight = w;
}


function turtleFace(angle) {
    this.angle = angle;
}


function makeTurtle(tx, ty, tColor,tStroke) {
    var turtle = {x: tx, y: ty,
                  angle: 0.0,
                  penIsDown: true,
                  color: tColor,
                  weight: tStroke,
                  left: turtleLeft, right: turtleRight,
                  forward: turtleForward, back: turtleBack,
                  penDown: turtlePenDown, penUp: turtlePenUp,
                  goto: turtleGoTo, angleto: turtleAngleTo,
                  turnToward: turtleTurnToward,
                  distanceTo: turtleDistTo, angleTo: turtleAngleTo,
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  face: turtleFace};
    return turtle;
}

This is one of the image I created.

screen-shot-2016-11-11-at-11-00-27-pm
Sample Image

Project 11 Lydia Jin

sketch

//Lydia Jin
//Section D
//jialuj@andrew.cmu.edu
//Project 11
var myTurtle1;
var flag=false;
function setup(){
    createCanvas(600,600);
    background('black');
    //create 5 turtles that does different things
    myTurtle1=new makeTurtle();
    noLoop();
    }
function draw(){

    strokeJoin(MITER);

    myTurtle1.setColor('silver');
    myTurtle1.setWeight(2);
    //draw stars
    for (i=0;i<50;i++){
      ellipse(random(width),random(height),3,5);
    }
}
//draws constellation when mouse pressed
function mousePressed(){
  noStroke();
  fill('silver');
  var x=mouseX;
  var y=mouseY;
  ellipse(x,y,8,8);
  stroke(0);
  if (flag==false){
      myTurtle1.penDown();
      myTurtle1.goto(x,y);  
  } else{
    //resets the pen
    flag=false;
    myTurtle1.penUp();
    myTurtle1.goto(x,y);
  }
  
        
}
//resets the status when key is pressed
function keyPressed(){
    if (flag==false){
      flag = true;
    } 
}

//////////////////////////////////////////////////////////////////////////////////////////////
function turtleLeft(d) {
    this.angle -= d;
}
 
 
function turtleRight(d) {
    this.angle += d;
}
 
 
function turtleForward(p) {
    var rad = radians(this.angle);
    var newx = this.x + cos(rad) * p;
    var newy = this.y + sin(rad) * p;
    this.goto(newx, newy);
}
 
 
function turtleBack(p) {
    this.forward(-p);
}
 
 
function turtlePenDown() {
    this.penIsDown = true;
}
 
 
function turtlePenUp() {
    this.penIsDown = false;
}
 
 
function turtleGoTo(x, y) {
    if (this.penIsDown) {
      stroke(this.color);
      strokeWeight(this.weight);
      line(this.x, this.y, x, y);
    }
    this.x = x;
    this.y = y;
}
 
 
function turtleDistTo(x, y) {
    return sqrt(sq(this.x - x) + sq(this.y - y));
}
 
 
function turtleAngleTo(x, y) {
    var absAngle = degrees(atan2(y - this.y, x - this.x));
    var angle = ((absAngle - this.angle) + 360) % 360.0;
    return angle;
}
 
 
function turtleTurnToward(x, y, d) {
    var angle = this.angleTo(x, y);
    if (angle < 180) {
        this.angle += d;
    } else {
        this.angle -= d;
    }
}
 
 
function turtleSetColor(c) {
    this.color = c;
}
 
 
function turtleSetWeight(w) {
    this.weight = w;
}
 
 
function turtleFace(angle) {
    this.angle = angle;
}
 
 
function makeTurtle(tx, ty) {
    var turtle = {x: tx, y: ty,
                  angle: 0.0, 
                  penIsDown: true,
                  color: color(128),
                  weight: 1,
                  left: turtleLeft, right: turtleRight,
                  forward: turtleForward, back: turtleBack,
                  penDown: turtlePenDown, penUp: turtlePenUp,
                  goto: turtleGoTo, angleto: turtleAngleTo,
                  turnToward: turtleTurnToward,
                  distanceTo: turtleDistTo, angleTo: turtleAngleTo,
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  face: turtleFace};
    return turtle;
}

This canvas represents a night sky in the universe. The user can create constellations using the turtle by clicking the mouse and connecting the dots. Once you finish one drawing, you can press any key and start on a new constellation. Below are two finished drawings:

screenshot-1

screenshot2

Liu Xiangqi-Project-11

sketch

/*Liu Xiangqi Section A xiangqil@andrew.cmu.edu Assignment-10-A*/
function turtleLeft(d) {
    this.angle -= d;
}
 
 
function turtleRight(d) {
    this.angle += d;
}
 
 
function turtleForward(p) {
    var rad = radians(this.angle);
    var newx = this.x + cos(rad) * p;
    var newy = this.y + sin(rad) * p;
    this.goto(newx, newy);
}
 
 
function turtleBack(p) {
    this.forward(-p);
}
 
 
function turtlePenDown() {
    this.penIsDown = true;
}
 
 
function turtlePenUp() {
    this.penIsDown = false;
}
 
 
function turtleGoTo(x, y) {
    if (this.penIsDown) {
      stroke(this.color);
      strokeWeight(this.weight);
      line(this.x, this.y, x, y);
    }
    this.x = x;
    this.y = y;
}
 
 
function turtleDistTo(x, y) {
    return sqrt(sq(this.x - x) + sq(this.y - y));
}
 
 
function turtleAngleTo(x, y) {
    var absAngle = degrees(atan2(y - this.y, x - this.x));
    var angle = ((absAngle - this.angle) + 360) % 360.0;
    return angle;
}
 
 
function turtleTurnToward(x, y, d) {
    var angle = this.angleTo(x, y);
    if (angle < 180) {
        this.angle += d;
    } else {
        this.angle -= d;
    }
}
 
 
function turtleSetColor(c) {
    this.color = c;
}
 
 
function turtleSetWeight(w) {
    this.weight = w;
}
 
 
function turtleFace(angle) {
    this.angle = angle;
}
 
 
function makeTurtle(tx, ty) {
    var turtle = {x: tx, y: ty,
                  angle: 0.0, 
                  penIsDown: true,
                  color: color(128),
                  weight: 1,
                  left: turtleLeft, right: turtleRight,
                  forward: turtleForward, back: turtleBack,
                  penDown: turtlePenDown, penUp: turtlePenUp,
                  goto: turtleGoTo, angleto: turtleAngleTo,
                  turnToward: turtleTurnToward,
                  distanceTo: turtleDistTo, angleTo: turtleAngleTo,
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  face: turtleFace};
    return turtle;
}


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

function draw() {
     background(0);

    var turtle5 = makeTurtle(mouseX, 200);
    turtle5.penDown();
    turtle5.setColor(255);
    turtle5.setWeight(6);
    turtle5.penDown();
    
        turtle5.face(-90);
        turtle5.forward(200-mouseY);
        turtle5.face(0);
        turtle5.forward(35);
        turtle5.face(90);
        turtle5.forward(25);
        turtle5.face(180);
        turtle5.forward(15);
        turtle5.face(-90);
        turtle5.forward(10);
        turtle5.face(0);
        turtle5.forward(7);
        turtle5.face(-90);
        turtle5.forward(7);
        turtle5.face(180);
        turtle5.forward(18);
        turtle5.face(90);
        turtle5.forward(200-mouseY-8);
        turtle5.face(0);
        turtle5.forward(40);
        
    
}

Looking Outwards 11 Lydia Jin

Computational Design of Metallophone Contact Sounds

I found this interesting computational design of sound online at this website. This project uses the technology of 3D printing to create specified shapes that makes sound. The parts include 3 sub parts: the mallet, fabricated shape, and the optimized stand. The parts have animal shapes that are very precisely calculated to make sure the best outcome of the sound comes out. It combines engineering and acoustic design skills. The project was created in 2013 and from this work, we can assume that the artist pays heavy attention to detail. I really like this project because it combines music and art in the most creative ways. And I admire how precise the pieces are, especially when it is made using innovative technology such as 3D printing.

mdambruc-Project-11

sketch

//Mairead Dambruch
//mdambruc@andrew.cmu.edu
//Section C
//Project-11-A
function turtleLeft(d) {
    this.angle -= d;
}


function turtleRight(d) {
    this.angle += d;
}


function turtleForward(p) {
    var rad = radians(this.angle);
    var newx = this.x + cos(rad) * p;
    var newy = this.y + sin(rad) * p;
    this.goto(newx, newy);
}


function turtleBack(p) {
    this.forward(-p);
}


function turtlePenDown() {
    this.penIsDown = true;
}


function turtlePenUp() {
    this.penIsDown = false;
}


function turtleGoTo(x, y) {
    if (this.penIsDown) {
      stroke(this.color);
      strokeWeight(this.weight);
      line(this.x, this.y, x, y);
    }
    this.x = x;
    this.y = y;
}


function turtleDistTo(x, y) {
    return sqrt(sq(this.x - x) + sq(this.y - y));
}


function turtleAngleTo(x, y) {
    var absAngle = degrees(atan2(y - this.y, x - this.x));
    var angle = ((absAngle - this.angle) + 360) % 360.0;
    return angle;
}


function turtleTurnToward(x, y, d) {
    var angle = this.angleTo(x, y);
    if (angle < 180) {
        this.angle += d;
    } else {
        this.angle -= d;
    }
}


function turtleSetColor(c) {
    this.color = c;
}


function turtleSetWeight(w) {
    this.weight = w;
}


function turtleFace(angle) {
    this.angle = angle;
}


function makeTurtle(tx, ty) {
    var turtle = {x: tx, y: ty,
                  angle: 0.0,
                  penIsDown: true,
                  color: color(128),
                  weight: 1,
                  left: turtleLeft, right: turtleRight,
                  forward: turtleForward, back: turtleBack,
                  penDown: turtlePenDown, penUp: turtlePenUp,
                  goto: turtleGoTo, angleto: turtleAngleTo,
                  turnToward: turtleTurnToward,
                  distanceTo: turtleDistTo, angleTo: turtleAngleTo,
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  face: turtleFace};
    return turtle;
}
var hotdog = [];//hotdog array
var turtle1;
var startFrame;
var lightening;//sound file

function preload(){
//  lightening2 = loadSound("lightening2.wav");//background sound
}

function setup() {
    createCanvas(800, 400);
    background(0);
  //  lightening2.play(0, 1, 2);//background sound
    for (var i = 0; i < 100; i++){
      var hotdogplace = random(width);
      hotdog[i]= makehotdog(hotdogplace);
      turtle1 = makeTurtle(mouseX, mouseY);//create turtle
      turtle1.setColor(color(255));
      turtle1.setWeight(2);
      turtle1.penDown();//creating lightening turtle
      resetCanvas();
      frameRate(100);
}
}
function draw() {
  //creating striped background
  colorMode(RGB);
  noStroke();
  from = color(48, 138, 191);
  to = color(200, 255, 50);
  interA = lerpColor(from, to, .33);
  interB = lerpColor(from, to, .66);
  fill(from);
  rect(0, 0, width, 100);
  fill(interA);
  rect(0, 100, width, 200);
  fill(interB);
  rect(0, 200, width, 300);
  fill(to);
  rect(0, 300, width, 400);
  sloth();
  updateandcreatehotdogs();
  removehotdog();
  addnewhotdog();
  showhotdog();
  makehotdog();
  //draws lightening
  var step = (random(width) - random(height));
  turtle1.forward(step);
  turtle1.left(1000);
  if (turtle1.y > width || turtle1.x > height)
  resetCanvas();
}
function resetCanvas(){//creates flashing background after turtle is drawn
  background(0);
  startFrame = frameCount;
  turtle1.penUp();
  turtle1.goto(400, 300);
  turtle1.penDown();
}
function updateandcreatehotdogs(){
    for (var i = 0; i < hotdog.length; i = i + 20){
        hotdog[i].move();
        hotdog[i].display();
}
}
function removehotdog(){ //removes hotdogs after past canvas
    var hotdogToKeep = [];
    for (var i = 0; i < hotdog.length; i++){
        if (hotdog[i].x + hotdog[i].breadth > 0) {
            hotdogToKeep.push(hotdog[i]);
    }
    }
    hotdog = hotdogToKeep;
}
function addnewhotdog() {
    var newhotdogProbability = 0.5;
    if (random(0, 1) < newhotdogProbability) {
        hotdog.push(makehotdog(width));
    }
}
function hotdogmove() {
    this.x += this.speed;
}
function showhotdog() {
    var hotdogHeight = 10;

	  push();
    noStroke();

    //draws four lines of hotdogs

    translate(this.x, 30);
    fill(255, 111, 91);
    ellipse(0, hotdogHeight, 25, 7);
    rectMode(RADIUS);
    fill(240, 182, 66);
    rect(0, hotdogHeight+2, 8, 3);

    translate(this.x, 80);
    fill(255, 111, 91);
    ellipse(0, hotdogHeight, 25, 7);
    rectMode(RADIUS);
    fill(240, 182, 66);
    rect(0, hotdogHeight+2, 8, 3);

    translate(this.x, 100);
    fill(255, 111, 91);
    ellipse(0, hotdogHeight, 25, 7);
    rectMode(RADIUS);
    fill(240, 182, 66);
    rect(0, hotdogHeight+2, 8, 3);

    translate(this.x, 130);
    fill(255, 111, 91);
    ellipse(0, hotdogHeight, 25, 7);
    rectMode(RADIUS);
    fill(240, 182, 66);
    rect(0, hotdogHeight+2, 8, 3);

    pop();
}
function makehotdog(LocationX) {
    var hdog = {x: LocationX,
                breadth: 1000,
                speed: -1.0,
                nstars: round(random(2,8)),
                move: hotdogmove,
                display: showhotdog}
    return hdog;
}
function sloth(x, y){
  //draws sloth
  x = 400;
  y = 350;
  noStroke();
  fill(140, 70, 0);
  ellipse(x, y, 20, 50);
  ellipse(x, y - 40, 30, 30);
  ellipse(x, y + 10, 35, 30);
  //face and body
  ellipse(x + 7, y + 20, 10, 20);
  ellipse(x - 7, y + 20, 10, 20);
  fill(255, 218, 117);
  ellipse(x, y - 40, 20, 20);
  //innerface
  fill(214, 135, 32);
  ellipse(x, y - 40, 17, 8);
  ellipse(x, y - 37, 10, 10 )
  //surrounding eye area
  fill(0);
  ellipse(x - 5, y - 40, 5, 5);
  fill(0);
  ellipse(x + 5, y - 40, 5, 5);
  //eyes
  fill(0);
  ellipse(x + 1, y - 37, 2, 2);
  fill(0);
  ellipse(x - 1, y - 37, 2, 2);
  //nostrils
  noStroke();
  fill(255, 0, 0);
  arc(x, y-34, 5, 5, TWO_PI, PI, CHORD);
  //mouth
}

For this project, I created a sloth-like creature that is continuously getting electrically shocked in the head by lightening in a hotdog storm. The lightening is created by turtles. I originally had lightening sounds that accompanied this project but was unable to have that due to the need of a local server.

Here is a screenshot of the project

screen-shot-2016-11-11-at-10-08-22-pm