Fibonacci Sequence

Fibonacci Sequence
// Released under the MIT licence
// mit-license.org/
// you can use this for commercial gain if you like eg you can sell artworks with this image.

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
// Released under the MIT licence 
// https://mit-license.org/
// you can use this for commercial gain if you like eg you can sell artworks with this image.
// https://turtletoy.net/turtle/29087990aa
// https://turtletoy.net/user/rupertxrussell

// https://en.wikipedia.org/wiki/Fibonacci_sequence
// A tiling with squares whose side lengths are successive Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13 and 21
// https://en.wikipedia.org/wiki/Fibonacci_sequence#/media/File:Fibonacci_Squares.svg

Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();
const scale = 1.3;
turtle.penup();
turtle.goto(-32 * scale,-12 * scale);
turtle.pendown();
   
sqRight(1);
sqRight(1);
sqRight(2);
sqRight(3);
sqRight(5);
sqRight(8);
sqRight(13);
sqRight(21);
sqRight(34);
sqRight(55);
sqRight(89);

function sqRight(n){
   turtle.circle(n * scale, extent = -90);
   for (var i = 0; i < 4; i++) {
       turtle.forward(n * scale);
       turtle.right(90);
   }
}