project 11

sketch

//Zhuoying Lin
//zhuoyinl@andrew.cmu.edu
//section a 
//project 11


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

    frameRate(10);
}

function draw() {

    for (var i=0;i<30;i++) {
        strokeWeight(15);
        stroke(220-i);
        line(0,i*15,width,i*15);
    }//background color

    push();
    var turtle = makeTurtle(0, 45);
    turtle.penDown();
    turtle.setColor(255);
    turtle.setWeight(3);
    strokeJoin(MITER);
     strokeCap(PROJECT);
    var i = 0;
    while ( i < width) {
        i++;
        turtle.left(90);
        turtle.forward(40);
        turtle.right(90);
        turtle.forward(40);
        turtle.right(90);
        turtle.forward(30);
        turtle.right(90);
        turtle.forward(20);
        turtle.right(90);
        turtle.forward(10);
        turtle.right(90);
        turtle.forward(10);
        turtle.left(90);
        turtle.forward(10);
        turtle.left(90);
        turtle.forward(20);
        turtle.left(90);
        turtle.forward(30);
        turtle.left(90);
        turtle.forward(40);

    }
    noLoop();
    turtle.penUp();
    pop();//upper frame

    push();
    var turtle = makeTurtle(0, height-5);
    turtle.penDown();
    turtle.setColor(255);
    turtle.setWeight(3);
    strokeJoin(MITER);
     strokeCap(PROJECT);
    var i = 0;
    while ( i < width) {
        i++;
        turtle.left(90);
        turtle.forward(40);
        turtle.right(90);
        turtle.forward(40);
        turtle.right(90);
        turtle.forward(30);
        turtle.right(90);
        turtle.forward(20);
        turtle.right(90);
        turtle.forward(10);
        turtle.right(90);
        turtle.forward(10);
        turtle.left(90);
        turtle.forward(10);
        turtle.left(90);
        turtle.forward(20);
        turtle.left(90);
        turtle.forward(30);
        turtle.left(90);
        turtle.forward(40);

    }
    noLoop();
    turtle.penUp();
    pop();//bottom frame
    
    
}

function mousePressed()  {
    var turtle = makeTurtle(mouseX, mouseY);
    turtle.penDown();
    turtle.setColor(255);
    for (var i = 0; i < 20; i++) {
        turtle.forward(50);
        turtle.right(137.5);
        turtle.forward(50); 
    }
    turtlePenUp();
    //make random turtles

}



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 tried to use turtle to create some abstract graphic that could interact with mouse motion. I use the turtle to make frames and another turtle to follow the mouse movement. whenever the mouse is pressed, a new turtle is drawn.

%e5%be%ae%e4%bf%a1%e6%88%aa%e5%9b%be_20161112235419

Leave a Reply