rsp1-Project-Compostion-Turtle-Freestyle

sketch

/*Rachel Park
rsp1@andrew.cmu.edu
Section B @ 10:30AM
Project 11: Turtle...anything*/

var myTurtle;//global variable for defining a new name for the turtle
function setup() {
  createCanvas(330,400);
  background(0);
  noLoop();
  myTurtle = new makeTurtle(width/2-50,20)//the turtle
}

function draw() {
  var dragon = dragonCurve(14);//variable to substitute in for function
  turtleDraw(dragon,200,90,2);//drawing the line
}

function dragonCurve(depth){//using L-system logic to create pattern
    if(depth === 0){
      return 'FX';}

    var turtle = dragonCurve(depth - 1);
    var newTurtle = '';
    for(var i = 0; i < turtle.length; i++){
        if(turtle.charAt(i) === 'X'){
            newTurtle += 'X+YF+';
        }
        else if (turtle.charAt(i) === 'Y'){
            newTurtle += '-FX-Y';
        }
        else {
            newTurtle += turtle.charAt(i);
        }
    }
    return newTurtle;
}


//------------------------------------------------
function turtleDraw(text, startx, starty, length) {//using turtle functions to draw out the patterns
    var direction = 0;
    var x = startx;//initial horizontal position of line
    var y = starty;//initial verticle position of line

    for(var i = 0; i < text.length; i++){

        if(text.charAt(i) === 'F'){
            //'F', draw forward length in direction
            var endx = x + length * Math.cos(direction * 0.017453292519);
            var endy = y + length * Math.sin(direction * 0.017453292519);

            var red = x/400 * 255;
            var green = y/400 * 255;
            var blue = (x + y + 300)/400 * 255;
            c = stroke(red,green,blue);
            myTurtle.setColor(c);//setting gradient color of lines

            line(x,y,endx,endy);//drawing the line
            x = endx;//reinitializing to new horizontal position
            y = endy;//reinitializing to new verticle position
        }
        else if(text.charAt(i) === '-'){
            //90 degrees added to direction
            direction += 90;
        }
        else if(text.charAt(i) === '+'){
            //90 degrees substracted from direction
            direction -= 90;
        }
    }
}
//-------------------------------------------------------
//other turtle functions

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 turtleReset(){
  this.reset = 0;
}

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,
    reset:turtleReset};

    return turtle;}

In searching for inspiration, I happened across the notion of the L-systems. I really liked how the visual of this specific patterned looked and wanted to try it out for myself. Although I did find resources to help me with the L-systems logic to generate the pattern because of its specific equations and such, I found that the over code was pretty straightforward in its use of the turtle graphics functions.

screenshot of final turtle graphic

katieche-project 11

katieche-10

var t1;
var t2;
var t3;

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

    // starts the turtle at a random location in the canvas
    t1 = makeTurtle(random(0, 480), random(0, 480));
    t2 = makeTurtle(random(0, 480), random(0, 480));
    t3 = makeTurtle(random(0, 480), random(0, 480));

    //puts pen down and sets colors and weight of each line
    t1.penDown();
    t1.setColor(color(190, 210, 240));
    t1.setWeight(3);
    t2.penDown();
    t2.setColor(color(200, 240, 210));
    t2.setWeight(3);
    t3.penDown();
    t3.setColor(color(250, 190, 210));
    t3.setWeight(3);
    frameRate(10);
}
 
function draw() {
    //starts making the turtle move
    t1.forward(10);
    t2.forward(10);
    t3.forward(10);
    //makes the turtle turn towards the mouse
    t1.turnToward(mouseX, mouseY, 10);
    t2.turnToward(mouseX, mouseY, 10);
    t3.turnToward(mouseX, mouseY, 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){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 just wanted to do something that reminded me of like things flying in the air, so I went with powerpuff girls colored lines that fly and do spins in the air. They fly following your mouse, and do circles in place when you mouse is not in motion.



aboyle-Project-11-Composition

aboyle composition

//Anna Boyle
//Section D
//aboyle@andrew.cmu.edu
//Project 11


var turtle;
var red=0;
var green=0;
var blue=0;
var lineWeight=6;

function setup() {
    createCanvas(480, 400);
    background(255)
    turtle = makeTurtle(0,height/2)
//creates borders to make it more ms paint-ish
    strokeWeight(2);
    line(width, 0, width, height);
    line(0, 0, 0, height);
    line(0, 0, width, 0);
    line(0, height, width, height)
//creates text
    textSize(10);
    text("M.S. Paint: Turtle Edition", 10, 20)
  }

//draws the line
function draw() {
    drawLine();
}

//function to draw the line
function drawLine(){
  //variable colors
    turtle.setColor(color(red, green, blue));
  //variable line weight
    turtle.setWeight(lineWeight);
  //makes the turtle constantly move toward the mouse
    turtle.forward(2);
    turtle.turnToward(mouseX, mouseY, 8);
}

function keyPressed(){
//press enter to restart turtle
   if (keyCode === ENTER){
      turtle = makeTurtle(mouseX,mouseY)
      drawLine();
//press up to make line thicker
    } if (keyCode === UP_ARROW){
      lineWeight++
      drawLine();
//press down to make line thinner
    } if (keyCode==DOWN_ARROW){
      lineWeight=lineWeight-1;
      drawLine();
    }
}

//type the first letter of a color to turn the line that color
//or in the case of black, the second letter

function keyTyped(){
    if (key === 'b'){
      blue = 255;
      red = 0;
      green = 0;
      drawLine();
    } if (key === 'r'){
      red = 255;
      blue = 0;
      green = 0;
      drawLine();
    } if (key === 'g'){
      green = 255;
      red = 0;
      blue = 0;
      drawLine();
    } if (key === 'y'){
      red = 255;
      green = 255;
      blue = 0;
    } if (key === 'p'){
      red = 145;
      green = 0;
      blue = 255;
    } if (key === 'o'){
      red=255;
      green=145;
      blue=0;
    } if (key=== 'l'){
      red = 0;
      green = 0;
      blue = 0;
    } if (key === 'w'){
      red=255;
      green=255;
      blue=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;
}

When thinking of an idea for this project, I thought about other drawing tools that I’ve used in the past. Eventually I got the idea to make this project visually emulate at least some aspects of MS Paint. In my final code, the turtle draws a line that constantly follows the mouse. You can make the line thicker and thinner, change the color, or restart the turtle with a different starting point. I added borders and text to drive home the visual similarities. When playing around with it, I couldn’t help but remember scribbling on MS Paint, so I think this one was a success. You can see screenshots of some scribbles I created below.

Playing around with color:

Playing around with restart:

Playing around with thickness:

All of the above:

sijings-project11-freestyleTurtle

sijings-Turtle

//Clair(sijing) Sun
//session C
//sijings@andrew.cmu.edu
//sijings-freestyle_turtle

//variables for each turtle
var turtle;
var turtle1;
var turtle2;
var turtle3;
var turtle4;
var turtle5;
var turtle6;
var turtle7;
var turtle8;
var backgroundt;
var backgroundt2;
var humanF;
var r=[250,249,237,122,250,219,216];//array of color where each turtle will 
var g=[222,223,215,137,224,166,131];//take individual color from the array
var b=[111,134,146,80,190,165,115];
var anglechange1=7;
var length1=10;

function setup() {
    createCanvas(480, 480);
    background(22,59,97);
    turtle = makeTurtle(width-20, 40);
    turtle1 = makeTurtle(width-39,60);
    turtle2 = makeTurtle(width-150, 40);
    turtle3 = makeTurtle(width-169,60);
    turtle4 = makeTurtle(40, height/2-40);
    turtle5 = makeTurtle(width-40, 40);
    turtle6 = makeTurtle(width-100, 110);
    turtle7 = makeTurtle(width-120, 150);
    turtle8 = makeTurtle(width-170, 50);
    backgroundt = makeTurtle(width-100, height-50);
    backgroundt2 = makeTurtle(100,50);
    humanF = makeTurtle(80,120);
    //moon
    turtle2.penDown();
    turtle2.setColor(color(r[2],g[2],b[2]));
    turtle2.setWeight(2);
    turtle2.left(50);
    for (var i=0; i<30;i++){
        turtle2.right(anglechange1);
        turtle2.forward(length1);
    }
    turtle2.right(120);
    turtle2.forward(2*length1);
    for (var i=0; i<7; i++){
        turtle2.left(10);
        turtle2.forward(2*length1);
    }
    turtle2.left(15);
    turtle2.forward(length1);
    turtle2.left(15);
    turtle2.forward(length1);

    //for stairs
    turtle4.penDown();
    turtle4.setWeight(5);
    for (var i = 0; i < 10; i++) {
        turtle4.setColor(color(random(r[3]-20,r[3]+20),g[3],b[3]));
        turtle4.right(90);
        turtle4.forward(10);
        turtle4.right(10);
        turtle4.forward(10);
        turtle4.left(10);
        turtle4.forward(10);
        turtle4.left(90);
        turtle4.forward(40);

    }

    //human figure that stands on the stair
    humanF.setColor(color(224,134,143));
    humanF.setWeight(3);
    for (var i = 0; i<8; i++){
        humanF.right(20);
        humanF.forward(5);
    }
    humanF.left(50);
    humanF.forward(5);
    humanF.left(90);
    humanF.forward(15);
    humanF.left(50);
    humanF.forward(25);
    humanF.left(50);
    humanF.forward(5);
    humanF.right(50);
    humanF.forward(5);
    humanF.right(50);
    humanF.forward(5);
    humanF.right(120);
    humanF.forward(5);
    humanF.right(120);
    humanF.forward(5);
    humanF.right(250);
    humanF.forward(5);
    humanF.left(25);
    humanF.forward(15);
    humanF.right(7);
    humanF.forward(25);
    humanF.left(17);
    humanF.forward(5);
    humanF.left(17);
    humanF.forward(5);
    humanF.left(17);
    humanF.forward(20);
    humanF.left(17);
    humanF.forward(20);
    humanF.left(27);
    humanF.forward(5);
    humanF.right(90);
    humanF.forward(5);
    humanF.right(20);
    humanF.forward(5);
    humanF.right(20);
    humanF.forward(5);
    humanF.right(20);
    humanF.forward(5);
    humanF.left(100);
    humanF.forward(18);
    humanF.left(70);
    humanF.forward(10);
    humanF.right(20);
    humanF.forward(5);
    humanF.right(50);
    humanF.forward(3);
    humanF.right(100);
    humanF.forward(10);
    humanF.left(10);
    humanF.forward(5);
    humanF.left(10);
    humanF.forward(5);
    humanF.right(110);
    humanF.forward(5);
    humanF.left(10);
    humanF.forward(22);
    humanF.left(80);
    humanF.forward(15);
    humanF.right(89);
    humanF.forward(15);
    humanF.left(5);
    humanF.forward(15);
    humanF.right(5);
    humanF.forward(15);
    humanF.left(5);
    humanF.forward(15);
    humanF.right(5);
    humanF.forward(15);
    humanF.right(5);
    humanF.forward(5);
    humanF.left(45);
    humanF.forward(5);
    for (var i=0; i<6; i++){
        humanF.right(16);
        humanF.forward(5);
    }   




    
}


function draw() {
    turtle.penDown();
    turtle1.penDown();
    //below are patterns around the moon (which can be controlled by mouse X and Y)
    
    for (var i = 0; i < 5; i++) {
        turtle.setColor(color(r[0]+i*20,g[0]+i*5,b[0],50));//have 50 at the end for certain transparency
        turtle.forward(mouseX/30);
        turtle.right(25);   
    }
    for (var i = 0; i < 20; i++) {
        turtle1.setColor(color(r[1]-i*2,g[1]-i*5,b[1],100));
        turtle1.forward(mouseX/100);
        turtle1.right(25);   
    }

    for (var i = 0; i < 20; i++) {
        turtle1.setColor(color(r[2]-i*2,g[2]-i*5,b[2],100));
        turtle1.forward(5);
        turtle1.right(25);   
    }

    //for drawing the background (two random generated lines)
    for (var i = 0; i < 20; i++) {
        backgroundt.setColor(color(r[2]-i*2,g[2]-i*5,b[2],20));
        backgroundt.forward(random(0,20));
        backgroundt.right(25);   
    }
    for (var i = 0; i < 20; i++) {
        backgroundt2.setColor(color(r[4],g[4],b[4],50));
        backgroundt2.forward(random(0,20));
        backgroundt2.left(25);   
    }

    for (var i = 0; i < 20; i++) {
        turtle5.setColor(color(r[4],g[4],b[4],30));

        turtle5.forward(mouseX/50);
        turtle5.right(25);   
    }  
    for (var i = 0; i < 20; i++) {
        turtle6.setColor(color(r[5],g[5],b[5],10));
        turtle6.forward(mouseX/50);
        turtle6.right(25);   
    }  

    for (var i = 0; i < 20; i++) {
        turtle7.setColor(color(r[6],g[6],b[6],30));
        turtle7.forward(mouseX/30);
        turtle7.right(25);   
    } 

    for (var i = 0; i < 20; i++) {
        turtle8.setColor(color(r[7],g[7],b[7],10));
        turtle8.forward(mouseX/40);
        turtle8.right(25);   
    }  

    for (var i = 0; i < 20; i++) {
        turtle8.setColor(color(r[7],g[7],b[7],10));
        turtle8.forward(5);
        turtle8.right(25);   
    } 

}

//below codes are directly from turtle graph lecture from 15-104 website

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 assignment, I wanted to explore the difference between turtles and the drawing method we have used in the past. I want to create a turtle which responds to the cursor. I found that with turtles, I can generate more detailed and “hand-drawing” like drawings. Thus, I have the inspiration coming from the Dreamworks.

I want to build some interactions between a human figure and the moon. But the style here is aimed to be old, decorative, and detailed. Thus, I thought about creating patterns along the moon and patterns in the background. Depending on the concentration of the patterns, different feelings can be generated (sometimes like fog). Some patterns (the ones in the background) is automatically generated. And other patterns (the ones around the moon) is generated according to the users playing with their mouse.  By dragging the mouse to the right, the patterns grow. With more manipulations, the patterns become dense. Here is a draft that I had before I code the project.

Here are some versions that my freestyle turtle project generates.

Version one
Version 2
version 3

Project-11-Composition-Chickoff

sketch

//Cora Hickoff
//Section D
//chickoff@andrew.cmu.edu
//Project-11

function setup() {

    createCanvas(480, 480);
    background(200, 99, 88);

    textSize(15);
    fill(217, 255, 255);
    text("Click the Canvas!", 10, 20);
   
    r = random(255);

      //lilac "spider legs"
      var t1 = makeTurtle(width/2, height/2);

      t1.setColor(color(179, 178, 134, 3));
      t1.setWeight(10);

    for (var p = 0; p < 100; p++) {

        t1.forward(p*3);
        t1.penDown();
        t1.right(147);
        t1.penUp();
        t1.penDown();

    //creates more dense "spider legs"
    for (var i = 0; i < width; i++) {

        t1.forward(6);
        t1.left(120);
        t1.right(90);
        t1.forward(90);
    }

    //creates less dense/sparser "spider legs"
    //(these are the circular shapes, which are not angular)
    for (var i = 0; i < width; i++) {

        t1.forward(6);
        t1.left(5);
        t1.right(9);
        t1.forward(6);
    }

        t1.penUp();

  } 
   
}

function mousePressed() {

    r = random(109);
    //dark red clouds
    var t2 = makeTurtle(mouseX, mouseY);

    t2.setColor(color(r, 0, 0, 35));
    t2.setWeight(30);

      for (var i = 0; i < 30; i++) {
          
          t2.forward(10);
          t2.forward(23);
          t2.right(random(1, 180));
          t2.forward(20);
          t2.right(78);

      }
      
      //light blue lines
      var t3 = makeTurtle(mouseX, mouseY);

      t3.setColor(color(191, 230, 255, 20));
      t3.setWeight(2);

    for (var p = 0; p < 100; p++) {

        t3.right(random(14, 26));
        t3.forward(.5);
        t3.right(random(3, 40));
        t3.forward(200);

    }
}

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

When I began this project, I aimed to enjoy myself because the concept of Turtle Graphics is inherently fun. I knew that I wanted the program to be interactive, so I integrated the mousePressed function so that every time the user clicked, they would create these cloud/berry-shaped turtles. To make things more interesting, I added a randomness factor to the color and shape so that the canvas would never be uniform and the user would still have fun seeing what new turtles they create.

jamieh-Project-11-Composition

sketch

/*
Jamie Ho
jamieh@andrew.cmu.edu
10:30
Project 11
*/


var hexagons;       //creating variablefor turtle
var len = 50;       //length of each triangle side
var factor = 0.15;  //factor to increase len size by
var angle = 0;      //initial angle
var colour = 255;   //white
var cFactor = 0.45; //amount to decrease the whiteness by

function setup() {
    createCanvas(400, 400);
    hexagons = new makeTurtle(width*0.8, height*0.4); //position of hexagons
    noLoop();
}

function draw() {
    background(0);

    hexagons.penDown();
    for(var i = 0; i < 500; i++){
        drawHexagon(len);           //call function with parameter of length for size of hexagons
        hexagons.face(angle);       //rotate hexagons
        
        //updates
        colour -= cFactor;          //turning white into black
        len += factor*i;            //increasing length of each side of hexagon
        angle += 3;                 //increasing rotation
    }
    hexagons.penUp();

}


function drawHexagon(length){
    hexagons.penDown();
    hexagons.setWeight(1);
    //triangle
    for(var i = 0; i < 6; i++){     // i < 6 to create hexagon
        hexagons.setColor(colour);  //setting colour for hexagon which changes for each time it runs through for loop
        hexagons.forward(length);   //move forward by 'length' dimension
        hexagons.right(60);         //move pen right by 60 degrees
    }
    hexagons.penUp();
}


//________________________TURTLE

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

With the turtle graphics, I wanted to use hexagons, which is a very simple shape, and turn it into an abstracted drawing that makes the shape of the hexagon almost unrecognisable. I also wanted to make the code efficient with use of loops unlike the previous assignment 10A which required a lot of repeated lines of motion.

Below are images of the final product and other results I got from experimenting with composition.

final product
change in position
change in for loop condition

Project 11, odh

I chose to make two turtles that would follow the mouse to reveal and image below. I gave each turtle a different angle of rotation to give them a “dance-like” feel, while they reveal an abstract picture.

Final Image:

odhP11

//Owen D Haft
//Section D
//odh@andrew.cmu.edu
//Project 11

//Declares the image
var abstract;

//Declares the turtles
var turtle1;
var turtle2;

function preload() {
    abstract = loadImage("https://i.imgur.com/ve9JtKn.jpg");
}

function setup() {
    createCanvas(480, 480);
    background(100, 100, 200);
    abstract.loadPixels();
    frameRate(20000);

    //Sets the start point of the turtles
    turtle1 = makeTurtle(width/2, height/2);
    turtle2 = makeTurtle(width/2, height/2);
}

function draw() {

    //Pulls the color from the image
    var color1 = abstract.get(turtle1.x, turtle1.y); //Gets the color from the image 
    var color2 = abstract.get(turtle2.x, turtle2.y);

    turtle1.setColor(color1);
    turtle1.setWeight(10);

    turtle2.setColor(color2);
    turtle2.setWeight(10);

//Turtles move towards the mouse
    turtle1.forward(10);
    turtle2.forward(10);

//Target is the mouse location
    var targetX = mouseX;
    var targetY = mouseY;

    turtle1.turnToward(targetX, targetY, 4); 
    turtle2.turnToward(targetX, targetY, 6); 
}


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

rkondrup-project-11-Composition

sketch

// ryu kondrup
// rkondrup@andrew.cmu.edu
// sectionD
// assignment10A

// makeTurtle(x, y) -- make a turtle at x, y, facing right, pen down
// left(d) -- turn left by d degrees
// right(d) -- turn right by d degrees
// forward(p) -- move forward by p pixels
// back(p) -- move back by p pixels
// penDown() -- pen down
// penUp() -- pen up
// goto(x, y) -- go straight to this location
// setColor(color) -- set the drawing color
// setWeight(w) -- set line width to w
// face(d) -- turn to this absolute direction in degrees
// angleTo(x, y) -- what is the angle from my heading to location x, y?
// turnToward(x, y, d) -- turn by d degrees toward location x, y
// distanceTo(x, y) -- how far is it to location x, y?



//global variables
var brighten = 25;
var x = [];
var y = [];
var starSize = [];




//TURTLE CODE
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,
                  setColor: turtleSetColor, setWeight: turtleSetWeight,
                  face: turtleFace};
    return turtle;
}

//massive red world
function zoom1() {
    //to chase the other worlds
    t1.turnToward((t2.x + t3.x)/2,(t2.y + t3.y)/2, 1);
    t1.forward(sq(0.005*(68 - t1.distanceTo(t2.x, t2.y)/10)));
    t1.penUp();
    //for a dotted line, alternate penDown then penUp
    t1.turnToward((t2.x + t3.x)/2,(t2.y + t3.y)/2, 1);
    t1.forward(sq(0.005*(68 - t1.distanceTo(t2.x, t2.y)/10)));
    t1.penDown();

}
//medium orange world
function zoom2() {
    //to chase the other worlds
    t2.turnToward((t1.x + t3.x)/2,(t1.y + t3.y)/2, 1);
    t2.forward(5*sq(0.01*(68 - t2.distanceTo(t1.x, t1.y)/10)));
    t1.penUp();
    //for a dotted line, alternate penDown then penUp
    t2.turnToward((t1.x + t3.x)/2,(t1.y + t3.y)/2, 1);
    t2.forward(5*sq(0.01*(68 - t2.distanceTo(t1.x, t1.y)/10)));
    t1.penDown();

}

//tiny pink world
function zoom3() {
    //to chase the other worlds
    t3.turnToward((t1.x + t2.x)/2,(t1.y + t2.y)/2, 1);
    t3.forward(5*sq(0.02*(68 - t2.distanceTo(t1.x, t1.y)/10)));
    t1.penUp();
    //for a dotted line, alternate penDown then penUp
    t2.turnToward((t1.x + t3.x)/2,(t1.y + t3.y)/2, 1);
    t2.forward(5*sq(0.02*(68 - t2.distanceTo(t1.x, t1.y)/10)));
    t1.penDown();

}



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

//to put star positions and sizes into arrays
    for (var i = 0; i < 300; i++) {
        x.push(random(width));
        y.push(random(height));
        starSize.push(random(3));
    }

    //too many turtles ! define each turtle's start position
    t1 = makeTurtle(random(width/3, 2*width/3), random(height/3, 2*height/3));
    t2 = makeTurtle(random(width/3, 2*width/3), random(height/3, 2*height/3));
    t3 = makeTurtle(random(width/3, 2*width/3), random(height/3, 2*height/3));





    //to set the color and strokeweight of each turtle
    t1.setColor(color(28 + brighten, 38 + brighten, 79 + brighten));
    t1.setWeight(1);
    t2.setColor(color(28 + brighten, 38 + brighten, 79 + brighten));
    t2.setWeight(1);
    t3.setColor(color(28 + brighten, 38 + brighten, 79 + brighten));
    t3.setWeight(1);


}

function draw() {
    // var darkBlue = color(28, 38, 79);
    // var orange = color(237, 132, 45);
    // var red = color(201, 34, 80);
    // var purple = color(183, 62, 151);
    background(color(28, 38, 79));

//to draw same stars each frame
    for (var j = 0; j < x.length; j++) {
        fill(255);
        ellipse(x[j], y[j], starSize[j]);

    }

//to make the turtles each frame
    zoom1();
    zoom2();
    zoom3();
    noStroke();

    //massive red world
    fill(201, 34, 80); //red
    ellipse(t1.x, t1.y, 100); //massive
    //for the shine
    push();
    translate(-20, -15);
    fill(201 + brighten, 34 + brighten, 80 + brighten);
    rectMode(CENTER);
    rect(t1.x, t1.y, 12, 20, 5);
    pop();

    //medium orange world
    fill(237, 132, 45); //orange
    ellipse(t2.x, t2.y, 50); //medium
    //for the shine
    push();
    translate(-10, -7);
    fill(237 + brighten, 132 + brighten, 45 + brighten);
    rectMode(CENTER);
    rect(t2.x, t2.y, 4, 6, 2);
    pop();


    //tiny pink world
    fill(183, 62, 151); //purple
    ellipse(t3.x, t3.y, 20); //tiny
    //for the shine
    push();
    translate(-4, -4);
    fill(183 + brighten, 62 + brighten, 151 + brighten);
    ellipse(t3.x, t3.y, 2);
    pop();

}

In this project I wanted to challenge myself with the task of making turtles which interact with each other on the canvas. I eventually ended up with quasi-gravity, which i then expressed as shiny rubber planets zooming around the screen which speed up as they approach each other and slow down as they disperse. I am pretty happy with the result, and although it looks very simple in the end the process that took me to the end product was long and rife with console errors. In the future I would like to figure out how to prevent the edges of planets from intersecting, or maybe give them the ability to bounce off of each other.

ablackbu-section c-Project-11-Composition

press mouse

sketch

var galaxy

function preload() {
    galaxy = loadImage('https://i.imgur.com/W0T1NZk.jpg')
}

function setup() {
    createCanvas(360, 280);
    background(230);
    push()
    scale(.3)
    image(galaxy,0,0)
    pop()
}
    
function draw() {
    fill(255)
    noStroke()
    ellipse(mouseX,mouseY,3,3)

}

function mousePressed(){
    
    var tur1 = makeTurtle(mouseX,mouseY);
    tur1.setColor(color(random(150,255),random(150,255),random(150,255)));
    var w = 3;
    tur1.setWeight(w)
    var side = random(5,20)
    for(var i = 0; i < 100; i++) {
        tur1.penDown();
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.penUp();
        tur1.right(110);
        tur1.forward(side*.8);
        side *= 0.9;
        w *= 0.7
        tur1.setWeight(w);
        tur1. right(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;}

For this project on adapting turtles, I created a galaxy where the user is able to create stars and planets, the planets made are a similar turtle to the spiral one made in lab but these are hexagons that spiral in on each other and get smaller and lighter as they go.

yunzhous-project-11

forgot to put my code up:
sketch

//Kathy Song
//Section D
//yunzhous@andrew.cmu.edu
//Project-11

var col;//coolor of turtle
var myTurtle = [];//array to store turtles
var degree = 20;//turn by degree

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

function draw() {
  for(var i = 0; i < myTurtle.length; i++) {
    col = map(mouseX, 0, width, 0, 255);//color according to mouseX
    myTurtle[i].setColor(col);
    myTurtle[i].setWeight(2);
    myTurtle[i].penDown();
    myTurtle[i].forward(20);
    myTurtle[i].right(degree);
    degree += 2;//degree constantly changing
  }
}

function mouseDragged() {
  myTurtle.push(makeTurtle(mouseX, mouseY));//make new turtle when mouse is pressed
}



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 something that make turtles along the curve that mouse is dragged. Then the turtle automatically moves and create random visual effect. The color of the stroke would also be controlled by mouseX, giving the image a little variety. I intentionally used only greyscale to create a snow&tree effect (because I really want it to snow!)