Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Turtle Graphics [12/12]

This program answers the question: What if a bigger angle and random colors were used?

* * *

The procedure FW has a parameter named distance. It is defined at the end of the second part of the source code. It first calculates the motion vector v. The variable penPos contains the current position. Then a disc is drawn at the current position, and a line is drawn from current position to motion end position. Lastly, the current position is set to equal the motion end position.

The procedures LT and RT change the pen's direction. The direction is rotated according to the parameter angle. The pen's direction, stored in the variable penDir, must be a unit vector. Since rotating a vector doesn't change its length, the new direction vector should remain to be approximately a unit vector.

Loading...