Test Snowflake Arm Branches 005

Inspired by Dan Catt's work at: revdancatt.com/penplotter/036-snowflakes Dan's list of Pen Plotter Tools at: revdancatt.com/penplotter/

Log in to post a comment.

// rupertxrussell snowflakes reverse engineered from Dan Catt
// https://revdancatt.com/penplotter/036-Snowflakes
// see full list of Dan's Pen Plotter Tools at: https://revdancatt.com/penplotter/
// MIT Licence

Canvas.setpenopacity(-1); // Black background

let turtle = new Turtle();
let angle = 0 //min=0 max=360 step=1
let scale = 10 //min=2 max=20 step=0.5

turtle.penup();
turtle.goto(-50,25);
turtle.pendown();
turtle.setheading(angle); 

// save the current position and heading
initialX = turtle.xcor();
initialY = turtle.ycor();
initialHeading = turtle.heading();

// draw the full length of the arm
turtle.forward(scale * 7)

// return to initial position
turtle.jump(initialX,initialY)
turtle.setheading(initialHeading) 

circle(scale);
jumpForward(scale * 0.8);

triangle(scale)
jumpForward(scale);

square(scale)
jumpForward(scale * 1.5);

hexagon(scale)
jumpForward(scale * 1.5);

equalatralTriangle(scale)

function triangle(length){
    initialX = turtle.xcor();
    initialY = turtle.ycor();
    initialHeading = turtle.heading();
    
    turtle.setheading(initialHeading - 90) 
    turtle.forward(length /2);
    turtle.right(90 + 45);

    turtle.forward(length * 0.71);
    turtle.right(90);
    
    turtle.forward(length * 0.71);
    turtle.right(90 + 45);
    turtle.forward(length /2);
    turtle.setheading(initialHeading) 
}

function circle(radius){
    jumpForward(scale);
    heading = turtle.heading();
    turtle.setheading(heading + 90) 
    turtle.circle(radius * 0.5);
    turtle.setheading(initialHeading) 
}

function equalatralTriangle(length){
    initialX = turtle.xcor();
    initialY = turtle.ycor();
    initialHeading = turtle.heading();
    turtle.setheading(initialHeading + 90) 
    turtle.forward(length /2);
    turtle.left(120);
    turtle.forward(length * 1);
    turtle.left(120);
    turtle.forward(length * 1);
    
    turtle.left(120);
    turtle.forward(length /2);
    turtle.jump(initialX,initialY)
    turtle.setheading(initialHeading) 
}

function hexagon(length){
    initialX = turtle.xcor();
    initialY = turtle.ycor();
    initialHeading = turtle.heading();
    
    turtle.setheading(initialHeading - 60) 
    // reset the scale
    length = length * 0.6;
    
    turtle.forward(length);
    
    turtle.right(60) 
    turtle.forward(length);
    
    turtle.right(60) 
    turtle.forward(length);
    
    turtle.right(60)
    turtle.forward(length);
    
    turtle.right(60) 
    turtle.forward(length);
    
    turtle.right(60) 
    turtle.forward(length);
    
    turtle.jump(initialX,initialY)
    turtle.setheading(initialHeading) 
}

function square(length){
    initialX = turtle.xcor();
    initialY = turtle.ycor();
    initialHeading = turtle.heading();
    
    // reset the scale
    length = length * 0.7;
    
    turtle.setheading(initialHeading - 45) 
    turtle.forward(length);
    
    turtle.right(90) 
    turtle.forward(length);
    
    turtle.right(90) 
    turtle.forward(length);
    
    turtle.right(90) 
    turtle.forward(length);
    
    turtle.jump(initialX,initialY)
    turtle.setheading(initialHeading) 
}

function jumpForward(length){
    turtle.penup();
    turtle.forward(length);
    turtle.pendown();
}