Nina Yoo – Project 11 – Composition

sketch

/* Nina Lee Yoo
Section E
nyoo@andrew.cmu.edu
Project-11:A Composition*/

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


    }


function draw() {

	for (var t=0;t<10;t++){
    	turtle = makeTurtle(0,0)
    	turtle.penDown
    }
	
		var r = (random(0,200));
		var g = (random(50,100));
		var b = (random(100,150));
		
	
	


		turtle.setColor(color(r,g,b))
		turtle.setWeight(1)
		turtle.penDown()
		turtle.forward(mouseX)// moving the initial fowards with them mouseX
		turtle.right(50)
		turtle.forward(mouseY) //movingthesecondfoward(creating longer lengthfor th first line)
		turtle.right(50)
		turtle.forward(100)
		turtle.right(mouseX)//(manipulating the end of the string)
		turtle.forward(100)
		turtle.right(20)
		turtle.forward(100)

		

}







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


It was cool seeing how if you changed the points on the turtle with mouseX or mouseY how it affected the whole drawing. It was difficult to grasp the concept at first due to my idea of turtles being static, but when doing the project it has helped me understand the underlying idea of turtle.

Leave a Reply