Hannah K-Project 11

sketch-60.js

var turtle1;
var turtle2;
var turtle3;
var turtle4;
var turtle5;
var turtle6;
var turtle7;
var turtle8;
var turtle9;

function setup() {
    createCanvas(500, 500);
    turtle1 = makeTurtle(120, 60);
    turtle2 = makeTurtle(110, 230);
    turtle3 = makeTurtle(120, 350);
    turtle4 = makeTurtle(250, 75);
    turtle5 = makeTurtle(260, 210);
    turtle6 = makeTurtle(250, 375);
    turtle7 = makeTurtle(400, 60);
    turtle8 = makeTurtle(390, 230);
    turtle9 = makeTurtle(400, 350);
}


function draw() {

    // Draw the frame
    fill(255, mouseX, mouseY);
    rect(0, 0, width-1, height-1);

    // Creating turtle 1 / 9
    turtle1.penDown();
    turtle1.setColor(0); 
    for (var i = 0; i < 500; i++) {
        turtle1.forward(10);
        turtle1.right(50);
        turtle1.forward(40);
        if (i % 10 === 0) {
          turtle1.forward(15);
        }
    }

    // Creating turtle 2 / 9
    turtle2.penDown();
    turtle2.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle2.forward(10);
        turtle2.right(65);
        turtle2.forward(40);
        if (i % 10 === 0) {
          turtle2.forward(15);
        }
    }

    // Creating turtle 3 / 9
    turtle3.penDown();
    turtle3.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle3.forward(10);
        turtle3.right(50);
        turtle3.forward(40);
        if (i % 10 === 0) {
          turtle3.forward(15);
        }
    }

    // Creating turtle 4 / 9
    turtle4.penDown();
    turtle4.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle4.forward(10);
        turtle4.right(65);
        turtle4.forward(40);
        if (i % 10 === 0) {
          turtle4.forward(15);
        }
    }

    // Creating turtle 5 / 9
    turtle5.penDown();
    turtle5.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle5.forward(10);
        turtle5.right(50);
        turtle5.forward(40);
        if (i % 10 === 0) {
          turtle5.forward(15);
        }
    }

    // Creating turtle 6 / 9
    turtle6.penDown();
    turtle6.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle6.forward(10);
        turtle6.right(65);
        turtle6.forward(40);
        if (i % 10 === 0) {
          turtle6.forward(15);
        }
    }

    // Creating turtle 7 / 9
    turtle7.penDown();
    turtle7.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle7.forward(10);
        turtle7.right(50);
        turtle7.forward(40);
        if (i % 10 === 0) {
          turtle7.forward(15);
        }
    }

    // Creating turtle 8 / 9
    turtle8.penDown();
    turtle8.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle8.forward(10);
        turtle8.right(65);
        turtle8.forward(40);
        if (i % 10 === 0) {
          turtle8.forward(15);
        }
    }


    // Creating turtle 9 / 9
    turtle9.penDown();
    turtle9.setColor(0);
    for (var i = 0; i < 500; i++) {
        turtle9.forward(10);
        turtle9.right(50);
        turtle9.forward(40);
        if (i % 10 === 0) {
          turtle9.forward(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;}

This week for my project, I decided to make several repeating turtles with a changing background. It kind of reminds me of the pattern we had to create for a project in a past week. It was fun revisiting the use of turtles, and I enjoyed making turtles that looked totally different from the meanders we created for the assignment last week. I think the changing background adds a cool visual effect, and it was something I came up with during the course of making this project. I did not really start this project with an exact plan, like I usually do, but I enjoyed it nonetheless and feel much more comfortable using turtles now.

Leave a Reply