[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/WPfJljXa)
:sectnums:
:nofooter:
:toc: left
:icons: font
:data-uri:

:stem: latexmath

= Rep.04 -- Pinwheel Tiling

https://en.wikipedia.org/wiki/Pinwheel_tiling[Pinwheel tiling] -- defined by Charles Radin & John Conway -- leads to a _non-periodic_ tiling pattern, so the tiles will appear in infinitely many orientations.

The idea is to have a triangle with side lengths stem:[1], stem:[2] & stem:[\sqrt{5}]:

image::pics/basic_triangle.png[width=200]

Such a triangle can then be divided into five isometric copies by the delation of factor stem:[\frac{1}{\sqrt{5}}].
Or, put simply, five similar (same angles and relations) triangles can be inscribed.
This works for all triangles with a right angle and a stem:[1:2] relation.

You are going to implement an algorithm which can draw such a pinwheel tiling with arbitrarily sized triangles and subdivision steps.

In case you have forgotten, those are the labels of points, sides & angles of a triangle, as used below:

image::pics/triangle_labels.png[width=400]

== The improved `SmartTurtle`

To aid you on your quest (😏) our good old `Turtle` sent you their smarter cousin `SmartTurtle`!

NOTE: Thanks to the help of `SmartTurtle` this exercise is actually pretty easy...

This turtle works basically like the old one, but has learnt two new tricks:

. It can now tell you where on the canvas it is currently sitting
** `GetPosition`
. It is now able to _look_ at a specifc point, thus automatically determining the turning angle for you
** `LookAt`
. Finally, it also remembers how far it has traveled
** `TravelDistanceMeters`
** Only `Move` counts, `Teleport` is 'free'

== Task

The initial triangle has those dimensions:

* stem:[a = 400]
* stem:[b = 800]
* stem:[c = \sqrt{a^2 + b^2}]

Implement an algorithm, using `SmartTurtle`, to draw this triangle together with its subdivisions.

CAUTION: Don't use more movements than necessary, especially try to not walk the same path twice -- the `SmartTurtle` knows how far you had it walk and this distance will be displayed for all to see 😉

=== First subdivision

First attempt one subdivision => splitting the initial triangle into 5 similar ones covering the same area with the same dimensions.
This should look like this:

image::pics/level_1.png[]

TIP: If you implement the subdivision movements of the turtle wisely, there is no need to draw the 'outer' triangle since it is fully composed of the inner ones

=== `n` subdivisions

Since you have the first subdivision completed it is now time to subdivide the five triangles you just created.
And then subdivide those yet again!

image::pics/level_2.png[]

I'm sure you already guessed it, what we need here is a _recursive_ algorithm 😁

Adapt your previous program in such a way, that it will accept a _recursion depth_ -- how many subdivisions there will be, at least 1.
This, of course, means that the method(s) have to keep track how 'deep' they already are to know when to stop.

It also means, that the subdivision algorithm has to be _smart_, because the inner triangles will be sometimes be upside down -- in fact they will be roated in (theoretically, limited by recursion depth) an _infinite_ number of directions, that's what makes pinwheel tiling so awesome.

Five subdivisions would look like this:

image::pics/level_5.png[]

*Achieve this result, using a recursive algortihm and having the turtle travel as short a distance as possible!*

TIP: More than 5 levels of recursion will take your PC _quite_ some time to process 😉