function setup() {
createCanvas(480, 480);
frameRate(5);
}
function draw() {
//sunset palette
var r = 255 + 25 * sin(millis() / 1000.0 );
var g = 200 + 25 * sin(millis() / 1000.0 + HALF_PI);
var b = 150 + 25 * sin(millis() / 1000.0 - HALF_PI);
background (r,g,b);
//make a hill
noStroke();
fill(0);
arc(235, 480, 500, 200, PI, 0, OPEN);
//tree
t1 = makeTurtle(240,380);
t2 = makeTurtle(240, 230);
t3 = makeTurtle(240, 230);
t4 = makeTurtle(240, 230);
t5 = makeTurtle(240, 230);
t6 = makeTurtle(240, 230);
t7 = makeTurtle(240, 230);
t8 = makeTurtle(200, 230);
t1.setColor(0);
t1.setWeight(10);
t2.setWeight(4);
t2.setColor(0);
t3.setWeight(2);
t3.setColor(0);
t4.setColor(0);
t4.setWeight(4);
t5.setColor(0);
t5.setWeight(5);
t6.setColor(0);
t6.setWeight(3);
t7.setColor(0);
t7.setWeight(4);
t8.setColor(255);
t8.setWeight(3);
t7.left(95);
t7.forward(100);
t1.left(90);
t1.forward(150);
t2.left(150);
t2.forward(100);
t3.right(175);
t3.forward(130);
t4.left(175);
t4.forward(130);
t5.left(5);
t5.forward(130);
t6.left(25);
t6.forward(140);
t8.left(25);
t8.forward(140);
var i = 0;
while(i < 10){
t2.right(random(82, 90));
t2.forward(60);
t2.back(random(60, 70));
t2.left(55);
t2.forward(20);
t3.right(90);
t3.forward(random(40,60));
t3.back(30);
t3.left(45);
t3.forward(30);
t4.right(90);
t4.forward(60);
t4.back(60);
t4.left(45);
t4.forward(30);
t5.left(90);
t5.forward(60);
t5.back(60);
t5.left(45);
t5.forward(30);
t6.left(90);
t6.forward(60);
t6.back(60);
t6.left(45);
t6.forward(30);
t7.right(90);
t7.forward(60);
t7.back(random(30,60));
t7.left(130);
t7.forward(30);
t8.right(90);
t8.forward(60);
t8.back(60);
t8.left(130);
t8.forward(random(10,30));
i ++;
}
}
//turtle graphics template
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 started out by wanting to draw some spooky skeletal trees, but then I got bored of drawing straight lines the whole time and decided to make it a Dr. Seus-esque tree instead. I enjoyed making circular pathways with different branches. Best Quality: Its wiggles.