This is a doodle of mine that I have doodled in the corners of my notebooks and sketchbooks since my freshman year of high school. I was very excited to be able to doodle it in code!
data-width=’600′ data-height=’400′ index
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>p5.js vers 0.5.2, Edit index.html to Change This Title</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/p5.js"></script>
<!-- Uncomment the lines below to include extra p5 libraries, or
use template-all or template-all-min:
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/addons/p5.dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/addons/p5.sound.js"></script>
-->
<script src="sketch.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
data-width=’600′ data-height=’400′ sketch
//Arula Ratnakar
//Section C
//Turtle Composition
//aratnaka@andrew.cmu.edu
function setup() {
createCanvas(600, 400);
background(255);
var turtle = makeTurtle(width/2, height/2);
turtle.penDown();
turtle.setColor(0);
turtle.setWeight (4)
turtle.left(90)
turtle.forward(145)
turtle.right(135)
turtle.forward(16)
turtle.right(135)
turtle.forward(100)
turtle.right(90)
turtle.forward(16)
turtle.right(90)
turtle.forward(16)
turtle.right(90)
turtle.forward(75)
turtle.right(135)
turtle.forward(16)
turtle.right(135)
turtle.forward(150)
turtle.left(90)
turtle.forward(16)
turtle.left(90)
turtle.forward(16)
turtle.left(90)
turtle.forward(100)
turtle.left(135)
turtle.forward(16)
turtle.left(135)
turtle.forward(11.313708499)
turtle.forward(63.686291501)
turtle.left(90)
turtle.forward(16)
turtle.left(90)
turtle.forward(16)
turtle.left(90)
turtle.forward(20)
turtle.forward(120)
turtle.penUp()
}
function draw() {
}
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;}