Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Turtle Graphics [5/12]

Let's now add a diagonal line. The first issue is the direction of the pen. To make it go straight downwards, it first needs to be rotated by 30 degrees. Then, to change into diagonal direction, it needs to be changed by another 45 degrees.

What's the length of the diagonal line? The diagonal line is longer than the sides of the house, so the lenght must be bigger than 200, but how much exactly? The mathematics tells that the length of a diagonal of a square equals the side length multiplied by the square root of 2. The procedure sqrt calculates square roots, so the length of the diagonal equals 200*sqrt(2).

After that, the direction changes again and the line of length 200 is drawn.

Exercise: draw the other diagonal of the house.

Loading...