Alexandra Kaplan – Project 11 – Composition

Press any key to restart!

/*
Alexandra Kaplan
aekaplan@andrew.cmu.edu
Section C
Project - 11
*/

function setup() {
    createCanvas(480, 480);
    background(250, 90, 15);
    
}

function draw() {

    var ttl1 = makeTurtle(240,240);
    var ttl2 = makeTurtle(240,240);
    var ttl3 = makeTurtle(width + width / 2, 240);
    var ttl4 = makeTurtle(width, 245);
    var ttl5 = makeTurtle(width * 2, 240);
    var tt2ColR = map(mouseY, 0, height / 2, 200, 50);
    

    // sand 1
    ttl1.penDown();
    ttl1.setWeight(10)
    col1 = color(250, 220, 200);
    ttl1.setColor(col1);
    for(var i = 0; i < 10; i++){
        ttl1.forward(-mouseY / 4);
        ttl1.right(-mouseX /50); 
        ttl1.left(mouseX/100)  
    }
    
    //sky
    ttl2.penDown();
    ttl2.setWeight(20);
    col2 = color(tt2ColR, 150, 225);
    ttl2.setColor(col2);
    for(var j = 0; j < 200; j++){
        ttl2.forward(mouseY / 4);
        ttl2.right(-mouseX / 50);
    }

     //sand 3
    ttl3.penDown();
    ttl3.setWeight(10);
    col3 = color(250, 230, 190);
    ttl3.setColor(col3);
    for(var i = 0; i < 10; i++){
        ttl3.forward(-mouseY / 4);
        ttl3.right(-mouseX / 50); 
        ttl3.left(mouseX / 100)  
    }
    //sand 2
    ttl4.penDown();
    ttl4.setWeight(10);
    col4 = color(250, 230, 200);
    ttl4.setColor(col4);
    for(var i = 0; i < 10; i++){
        ttl4.forward(-mouseY / 5);
        ttl4.right(-mouseX / 50); 
        ttl4.left(mouseX / 100);  
    }

    ttl5.penDown();
    ttl5.setWeight(10);
    col5 = color(250, 220, 200);
    ttl5.setColor(col5);
    for(var i = 0; i < 10; i++){
        ttl5.forward(-mouseY / 4);
        ttl5.right(-mouseX / 50); 
        ttl5.left(mouseX / 100);
    }

}

function keyPressed(){
    background(240, 90, 15);

}

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;}

For this project, I wanted to focus on mouse interactivity and how turtles could be used to create an overall picture. Using a few different turtles, I was able to make a desert landscape with different colors of sand and a sun that can be included depending on the person using it.

earlier iteration
final iteration with crescent sun
Final iteration

Eunice Choe – Project-11 – Composition

sketch

/* Eunice Choe
Section E
ejchoe@andrew.cmu.edu
Project-11*/


var r;
var g;
var b;
var turtle =[];

function setup() {
    createCanvas(400, 400);
    background(255, 206, 198);
    for (var t = 0; t < 5; t ++) {
        turtle[t] = makeTurtle(width / 2, height / 2); // sets initial position
        turtle[t].penDown;
    }
}

function draw() {
    for (var t = 0; t < turtle.length; t ++) {
        r = random(100, 255);
        g = random(10, 255);
        b = random(50, 255);
        turtle[t].setColor(color(r, g, b)); // random turtle colors
        turtle[t].setWeight(random(-0.5, 5)); // random weights
        turtle[t].penDown();
        turtle[t].forward(random(10, 70)); // random lengths
        turtle[t].right(-100, 50); // random directions
        turtle[t].penUp();
  }
  frameRate(5);
}

function mousePressed()  {
    var turtle = makeTurtle(mouseX, mouseY);
    turtle.penDown();
    turtle.setColor(255);
    for (var i = 0; i < 20; i++) { // makes random white stroke shapes
        turtle.forward(random(10, 20));
        turtle.right(200);
        turtle.forward(random(10, 20));
    }
    turtlePenUp();
}

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;}

For my project, I wanted to create an abstract composition that shows a sense of randomness. I incorporated the randomness through randomized colors, strokes, and turtle directions. Someone interacting with this composition can also click the mouse and randomized white strokes will appear. Overall, I think the randomness makes the composition interesting.

The beginning of the composition.

The composition after some time passes and the added white strokes.

Lan Wei-Project 11-Composition

my-sketch.js

//Lan wei
//Section D
//lanw@andrew.cmu.edu
//Project-11

var img;
var repeatTime = 1; // time repeated before the painting is finished
var numEachTime = 10; // number of turtles in each repeat time
var randomYArrays = []; //nested arrays including Y in each repeat time
var randomY = []; //arrays of Y in each repeat time
var bri; //brightness of the pixel

function preload(){
    img = loadImage("https://i.imgur.com/9e7ATQI.jpg?1.jpg");
}

function setup() {
    createCanvas(450, 450);
    img.loadPixels();
    background(0);
    for (var i = 0; i < repeatTime; i ++){
        for (var j = 0; j < numEachTime; j ++){ //add "numEachTime" values in randomY
            randomY.push(random(0, height));
        }
        randomYArrays.push(randomY);
        randomY = [];
    }
    frameRate(1);
}

function draw() {
    for (var i = 0; i < repeatTime; i ++){
        randomY = randomYArrays[i];
        for (var n = 0; n < numEachTime; n ++){
            drawTurtle(-100, randomY[n]);
        }
    }
}

function drawTurtle(tx, ty){
    var ttl = makeTurtle(tx, ty);
    ttl.penDown();

    //step 1
    bri = brightness(img.get(ttl.x, ttl.y)); //brightness of the pixels
    ttl.setColor(map(bri, 0, 100, 255, 70));
    ttl.setWeight(map(bri, 0, 100, 1, 2)); //change light weight according to brightness
    ttl.forward(random(20, 50));

    //step 2
    for(var i = 0; i < 15; i ++){
        var angle = 0;
        while (angle < 30){
            var angleSingleTime = random(0, 20);
            ttl.left(angleSingleTime);
            bri = brightness(img.get(ttl.x, ttl.y)); //brightness of the pixels
            ttl.setColor(map(bri, 0, 100, 255, 70));
            ttl.setWeight(map(bri, 0, 100, 1, 2)); //change light weight according to brightness
            ttl.forward(random(1, 3));
            angle += angleSingleTime;
        }

        //step 3
        while (angle < 90){
            var angleSingleTime = random(0, 20);
            ttl.right(angleSingleTime);
            bri = brightness(img.get(ttl.x, ttl.y)); //brightness of the pixels
            ttl.setColor(map(bri, 0, 100, 255, 70));
            ttl.setWeight(map(bri, 0, 100, 1, 2)); //change light weight according to brightness
            ttl.forward(random(1, 3));
            angle += angleSingleTime;
        }

        //step 4
        while (angle < 120){
            var angleSingleTime = random(0, 20);
            ttl.left(angleSingleTime);
            bri = brightness(img.get(ttl.x, ttl.y)); //brightness of the pixels
            ttl.setColor(map(bri, 0, 100, 255, 70));
            ttl.setWeight(map(bri, 0, 100, 1, 2)); //change light weight according to brightness
            ttl.forward(random(1, 3));
            angle += angleSingleTime;
        }

        //step 5
        bri = brightness(img.get(ttl.x, ttl.y)); //brightness of the pixels
        ttl.setColor(map(bri, 0, 100, 255, 70));
        ttl.setWeight(map(bri, 0, 100, 1, 2)); //change light weight according to brightness
        ttl.forward(random(20, 50));
    }
}

/////////////////////////////////////////////////////////
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 planned to draw abstract ‘Sherlock’ with turtles. The process didn’t go smoothly. I tested different moving modes of the turtles and finally decided to use the one with some randomness but generally moving from the left of the canvas to the right. There are some aspects of the project that don’t reach my expectation (for example the nested loop might have some problems), but the result is good and the effect of old movie is kind of surprising.

Process Sherlock 1
Process Sherlock 2

Sophie Chen – Project 11 – Composition

sketch

// Sophie Chen
// Section C
// sophiec@andrew.cmu.edu
// Project 11

var turtle;

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


function draw() {
    
    turtle = makeTurtle(width / 2 + 50, height + 50)
    //gradient color
    var g = map(mouseY, 0, height, 255, 0);
    var r = map(mouseY, 0, width, 10, 155);
    var col = color(r, g, 200);

    turtle.setColor(col);
    turtle.setWeight(2);
    var navY = map(mouseY, 0, 480, 480, 0); // navigation Y to scale of canvas
    var navX = map(mouseX, 0, 480, 480, 0); // navigation X to scale of canvas

    // not visible, sets distance between blobs
    for (var i = 0; i < 100; i++) {
        turtle.penUp();
        turtle.forward(navY / 2);
        turtle.left(90.4);
        turtle.forward(navX); 
        turtle.penDown(); 

    // blobs along path of previous for loop
        for (var j = 0; j < 100; j++){
        	turtle.setWeight(0.3);
        	turtle.right(200.5);
        	turtle.forward(100);
        	turtle.right(19.1);
        }

    }
 
}

/////////////////////////////////////////////

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;}

For this project I wanted to use turtle graphics to create something that allows the user to draw something that looks 3d, made up of the 2d patterns. I tested out a lot of different variations and ended up liking this one the most (the slower you move the mouse, the smoother the gradient). Overall I had a lot of fun with this, I’m definitely a lot more comfortable with turtle graphics now.

different iteration
another different iteration
final version

Min Jun Kim- Project 11 Composition

Move the mouse!

/*
Min Jun Kim
minjubki
15104
Project 11

Makes a turtle composition
*/

var t1, t2; //initialize turtles
var turtles = []
var inc = 0.05 //used to control pace of sin
var v = 0.5 //value for sin
var ang; //angle
var xind = []; //index for x
var yind = []; // index for y
var sumx=0; //sum of x
var sumy =0 ; //sum of y
var topdistx = 0; //distance from a certain point 
var topdisty = 0; // y distance from a certain point 

function setup() {
     createCanvas(480, 480); 
    //sets up two turtles

    t1 = makeTurtle(width/2, height/2);
    t1.setWeight(2);
    t1.setColor(255);
    t1.penDown();

    t2 = makeTurtle(0, 0);
    t2.setWeight(1);
    t2.setColor(0);
    t2.penDown();
    frameRate(500);



}


function draw() {
    background(0);
    noFill();

    //draws the grid in the background
    while(t2.y < height+10) {
        t2.forward(width);
        t2.right(90);
        t2.forward(3);
        t2.right(90);
        t2.forward(width);
        t2.left(90);
        t2.forward(3);
        t2.left(90);
        
    }
    //repeat once it finishes
    if (t2.y > height) {
        t2.goto(0,0);
    }

    //have a repeating colorshift
    t2.setColor(sin(v)*200);

    //only have the drwaing if mouse is in canvas
    if (mouseX> width || mouseY > height) {
        t1.penUp();
    }
    else {t1.penDown()};
    
    //t1.setWeight(random(5))
    strokeWeight(1);
    //find angle to mouse
    ang = int(t1.angleto(mouseX,mouseY));
    distanco = dist(mouseX,mouseY, t1.x, t1.y);
    
    rect(0,0, width-1, height-1);
    t1.forward(10+distanco/ang);
    //make drawing shift if mouse is moving
    t1.turnToward(mouseX,mouseY,ang);
    t1.goto(width/2, height/2);
    
    //make sure it is in bounds
    if(t1.x > width || t1.x < 0) {
        t1.goto(random(width),random(height));
    }
    //draw the pattern in middle
    for (var i = 0; i < 200; i++) {
        t1.forward(mouseY/5);
        t1.right(mouseX/9+90); 
        t1.forward(sin(v)*mouseY/100);
        //index values
        xind[i] = t1.x;
        yind[i] = t1.y;
        //draw exoanding points
        if (i % 2 === 0) {
            t1.forward(distanco*cos(v));
            t1.left(2);
        }
        //inverse expanding points
        if (i % 5 === 0) {
            t1.forward(50*sin(v));
            t1.right(2);
        }
        
        //make sure it stays in center
        t1.goto(width/2, height/2);
    }
    //find sum of all points
    for (i = 0; i < xind.length; i++) {

        sumx += xind[i];
        sumy += yind[i];
        
        
    }
    //make the list not too big
    if (xind.length > 100) {
        xind.pop();
        yind.pop();
    }
    //find distance to cneter
    topdistx = dist(sumx/xind.length, 0, 240, 0);
    topdistx = dist(0, sumy/xind.length, 0, 240);
    //go to cneter of drawing
    t1.goto(sumx/xind.length,sumy/yind.length);
    fill(0);
    //reset
    sumx=0;
    sumy=0;

    //controls the value for the sin and return to 0 if too high
    v += inc;
    if (v > 100) { v= 0};

}



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 week I wanted to draw something that could be used a music video in relation to this week’s looking outwards. I first drew patterns in the middle that changed according to the position of the mouse, then added elements that were based on time. I decided to use sin and cos and increased it with a certain value. The value could be changed to make it beat faster, but it was too overwhelming that way. Then I drew a simple grid in the background, and added color elements to it. I think that this project turned out well, and I was shocked that turtle graphics can produce such detailed programs.

Progress pics:

Progress 1

Progress Two
Progress 3

Catherine Coyle – Project 11 – Composition

use arrow keys to generate spirals

// Catherine Coyle
// ccoyle@andrew.cmu.edu
// Section C
// Project 11 - Composition

//var numFlowers = Number(prompt('how many flowers?'));
var numFlowers = 1;
var pastNumFlow = 1;
var firstFlower;
var flowers = [];


function setup() {
  // put setup code here
  createCanvas(480,480);
  //print(numFlowers);
  firstFlower = makeFlower();
  flowers.push(firstFlower);
}

function draw() {
	background(177, 237, 196);
	for(var i = 0; i < numFlowers; i++) {
		flowers[i].draw();
	}
	fill(56, 112, 90);
	textSize(20);
	text('# of Flowers:', width / 2 - 50, height - 50);
	noStroke();
	fill(32, 76, 72);
	textSize(25);
	text('←  ' + numFlowers + '  →', width / 2 - 40, height - 10);
}

function keyPressed() {
	if (keyCode == RIGHT_ARROW) {
		pastNumFlow = numFlowers;
		numFlowers++;
		newFlower = makeFlower();
		flowers.push(newFlower);
	}
	if ((keyCode == LEFT_ARROW) & (numFlowers > 1)) {
		pastNumFlow = numFlowers;
		numFlowers -= 1;
	}
}

function makeFlower() {
	var f = {
		x: random(width),
		y: random(height),
		c: color(random(255), random(255), random(255)),
		petals: random(30, 200),
		r: random(5, 50),
		ang: random(100, 360),
		draw: drawFlower,
	}
	return f;
}

function drawFlower() {
	currFlow = makeTurtle(this.x, this.y);
	currFlow.setColor(this.c);
	for(var i = 0; i < this.petals; i++) {
		currFlow.forward(this.r);
		currFlow.right(this.ang);
	}
}



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 kind of had an idea for an abstract garden for this project. You use the arrow keys to control the amount of ‘flowers’ (randomized spirals) on the screen. I made an object to store the properties of all the spirals and then drew them with turtles. It’s really cool and interesting to see what kinds of patterns the program can come up with!

Here’s one example

Project 11 – Composition – Min Lee

index

var comb = 50;
var s = 25;
var bees = [];
var px = [];
var py = [];

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

    //sets each bees position

    for (var i = 0; i < 10; i++) {
    	px.push(random(0, width));
    	py.push(random(0, height));
    };

}

function draw() {
	background(199, 149, 68);

    strokeJoin(MITER);
    strokeCap(PROJECT);

    //draws dark lines on hive
	var ttl1 = makeTurtle(0, -300)
	ttl1.setColor("black");
	ttl1.setWeight(5);
	for (var y = 0; y < 30; y++) {
		for (var i = 0; i < 15; i++) {
			ttl1.penDown();
			ttl1.forward(s);
			ttl1.right(60);
			ttl1.forward(s);
			ttl1.left(60);
		};
		ttl1.penUp();
		ttl1.goto(0, y * 50 * sqrt(3) / 2 - 300);
	};

	//draws thin lines on hive
	var ttl2 = makeTurtle(0, -302)
	ttl2.setColor("black");
	ttl2.setWeight(0.5);
	for (var y = 0; y < 30; y++) {
		for (var i = 0; i < 15; i++) {
			ttl2.penDown();
			ttl2.forward(s);
			ttl2.left(60);
			ttl2.forward(s);
			ttl2.right(60);
		};
		ttl2.penUp();
		ttl2.goto(0, y * 50 * sqrt(3) / 2 - 300);
	};

	strokeCap(ROUND)

	//creates bees
	for (var i = 0; i < 10; i++) {
		//moves bees randomly
		fill(0);
		ellipse(px[i], py[i], random(10, 15), random(10, 15))
		px[i] += random(-1, 1);
		py[i] += random(-1, 1);


		//if bees are too close to edges, keep them from going off canvas
		if (px < 1) {
			px += random(0, 1);
		} else if (px > width - 1) {
			px += random(-1, 0);
		};

		if (py < 1) {
			py += random(0, 1);
		} else if (py > height - 1) {
			py += random(-1, 0);
		};
	};
}



//------------------------------------------------

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;
}

For this project I wanted to recreate a beehive’s hexagons and add bees, but I unfortunately ran out of time so I simplified the bees.

An initial sketch behind the math I was trying to figure out.

Shirley Chen-Project-11-Composition

sketch

// Shirley Chen
// Section B
// junfanc@andrew.cmu.edu
// Project-11


var myTtl = [];
var distance = 0;
var col;

function setup() {
  createCanvas(480, 480);
  background(100, 0, 0);
  frameRate(10);

}

function draw(){
  for(var i =0; i < myTtl.length; i++){
//Two geometries will be drawn alternatively according to the number of mouse click
//First geometry
    if (i % 2 == 0){
      col = map(mouseY, 0, height, 0, 255);
//Color will change according to mouseY
      myTtl[i].setColor(col);
      myTtl[i].setWeight(1);
      myTtl[i].penDown();
      myTtl[i].forward(distance);
      myTtl[i].right(45);
      distance += 1;
//The geometry will become larger and larger
    }
//Second geometry
    else{
      col = map(mouseY, 0, width, 0, 255);
      myTtl[i].setColor(col);
      myTtl[i].setWeight(1);
      myTtl[i].penDown();
      myTtl[i].forward(distance);
      myTtl[i].right(70);
//The direction of drawing the geometry goes backward
      distance -= 1;

    }
  }
}

function mouseClicked(){
//Draw a new geometry per mouse click
  myTtl.push(makeTurtle(mouseX, mouseY));
}



/////////////////////////////////////////
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(144, 255 , 210),
                  weight: 4,
                  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;
}

For this project, I use turtle to draw two different geometries. They appear alternatively according to the number of mouse clicked. As the geometries are drawn, the color of stroke changes gradually. And the starting color is based on the position of mouse X. Whenever the number of mouse clicked is even, the direction of the stroke would go backward so that the geometries that are already drawn will change color again. This project is a great practice for object command.

Yoo Jin Shin-Project-11-Composition

Project-11

// Yoo Jin Shin
// Section D
// yoojins@andrew.cmu.edu
// Project 11 Turtle Freesytle

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 particles = [];

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

    // Making particles/"rain"
    for (var i = 0; i < np; i++) {
        var p = makeParticle(200, 200,
                             random(-50, 50), random(-50, 50));
        particles.push(p);
    }
    frameRate(10);
}

function draw() { 
    // Gradient green/grass background based on mouse
    var r = map(mouseX, 0, width, 70, 120); 
    var b = map(mouseY, 0, height, 90, 120);
    background(r, 170, b);

    // Center rose on mouse
    var ttl = makeTurtle(mouseX, mouseY);
    ttl.penDown();
    ttl.setColor("pink");
    ttl.setWeight(1);
    ttl.left(frameCount);
    ttl.face(190);

    for (var i = 0; i < 25; i++) {
        ttl.face(225 - i * 100);
        for (var j = 0; j < 6; j++) {
            ttl.forward(3 + i * 2);
            ttl.left(80);
        }
    }
    ttl.penUp();

    /// Left smaller rose 
    var ttl2 = makeTurtle(mouseX - 50, mouseY);
    ttl2.penDown();
    ttl2.setColor(150);
    ttl2.setWeight(1);
    ttl2.left(frameCount);
    ttl2.face(190);

    for (var i = 0; i < 10; i++) {
        ttl2.face(225 - i * 100);
        for (var j = 0; j < 6; j++) {
            ttl2.forward(2 + i * 2);
            ttl2.left(70);
        }
    }
    ttl.penUp();

    /// Right smaller rose 
    var ttl2 = makeTurtle(mouseX + 50, mouseY);
    ttl2.penDown();
    ttl2.setColor(150);
    ttl2.setWeight(1);
    ttl2.left(frameCount);
    ttl2.face(190);

    for (var i = 0; i < 10; i++) {
        ttl2.face(225 - i * 100);
        for (var j = 0; j < 6; j++) {
            ttl2.forward(2 + i * 2);
            ttl2.left(70);
        }
    }
    ttl.penUp();

    // Draw all particles in the array
    if (mouseIsPressed) {
        var newp = makeParticle(mouseX, mouseY,
                                random(-10, 10), random(-10, 0));
        particles.push(newp);
    }

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

}

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 = 100;      // how many particles
var COLORS = ["White", "#86E3F2", "#37A3B5", "#357CA8", "#14608E"];

function particleStep() {
    this.age++;
    this.x += this.dx;
    this.y += this.dy;
    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 < 0) { // bounce off top
        this.y = -this.y;
        this.dy = -this.dy * springy;
    }
    this.dy = this.dy + gravity; // force of gravity
    var vs = Math.pow(this.dx, 2) + Math.pow(this.dy, 2);
    var d = vs * drag;
    d = min(d, 1);

    // Repelling force from center rose
    var rpx = mouseX;
    var rpy = mouseY;
    var d2 = dist(rpx, rpy, this.x, this.y);
    var rpc = 9000;
    var f = rpc / (Math.pow(d2, 2));
    var dirx = (this.x - rpx) / d2;
    var diry = (this.y - rpy) / d2;
    // scale dx and dy to include drag effect
    this.dx *= (1 - d);
    this.dx += dirx * f;
    this.dy *= (1 - d)
    this.dy +=  diry * f;
}

function particleDraw() {
  fill(this.particleColor);
  noStroke();
  ellipse(this.x, this.y, this.particleSize, this.particleSize);
  point(this.x, this.y);
}

function pickColor() {
  return COLORS[int(random(COLORS.length))];
}

function pickSize() {
  return random(5, 30);
}

// create a "Particle" object with position and velocity
function makeParticle(px, py, pdx, pdy) {
    p = {x: px,
       y: py,
         dx: pdx, 
         dy: pdy,
         age: 0,
         step: particleStep,
         draw: particleDraw,
         particleColor : pickColor(),
         particleSize : pickSize(),
        }
    return p;
}

I created this project with a flower garden in mind: there are rose-like shapes created using turtle, a green, grass-like background, and many blue, rain-like particles. There is a force around the center rose that repels the rain.

Repelling force

 

Project 11 Composition – Sara Frankel

sketch

var terrainSpeed = 0.00025; 
var terrainDetail = 0.001; 

function setup() {
    createCanvas(400, 200);
    frameRate(20); 

}

function draw() {
    background('lightblue');

    fill('orange');
    ellipse(width - 35, 35, 50, 50); //draws the sun

    noFill();
    beginShape(); //draws terrain at random of noise
    for (var x = 0; x < width; x++) {
        var t = (x * terrainDetail) + (millis() * terrainSpeed);
        var y = map(noise(t), 0, 1, height/2, height);
        vertex(x, y);
        stroke('blue');
        line(x, y, x, height); //fills terrain so that it appears blue
    }
    endShape();

    duck(mouseX, y - 10, 20); //draws "duck" in the row with specific different radius
    duck(mouseX - 100, y - 10, 10);
    duck(mouseX - 150, y - 10, 5);
    duck(mouseX - 200, y - 10, 15);

    
}

function duck(dx, dy, radius) {
    var ttl1 = makeTurtle(dx + radius, dy - radius);
    ttl1.penDown(); //puts pen down
    ttl1.setColor('yellow');//color is yellow
    ttl1.setWeight(6);

    ttl1.left(90);//rotates circle so that starting point is to right of the duck

    var increments = radius * 10;//variable that gives way so that each radious of duck is in proportion of other

    for (i = 0; i < increments; i++) {
        d = 1;
        ttl1.forward(d);
        ttl1.left(360/increments);// completes circle     
    }

    ttl1.setColor('orange');//draws nose
    ttl1.forward(radius);
    ttl1.right(120);
    ttl1.forward(radius);
    ttl1.right(120);
    ttl1.forward(radius);
    ttl1.right(120);
    ttl1.forward(radius);

    stroke(0); //draws eye
    strokeWeight(6);
    point(dx, dy - radius - 5);

    ttl1.penUp();
}


//_________________________________________________________

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;
}

For my project, I went in knowing I wanted to draw ducks floating on water. I did so by using turtle graphics to draw the duck and its beak and using parameters, to change the radius/size of each duck. Imaged is a “Family of Ducks Swimming Together on A Nice Day”. Here is an image of what it might look like.