Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Python: Turtle graphics and rsTurtle module
1. Python: Turtle graphics and rsTurtle module
I have always found it useful, in addition to creating a custom class for canvas drawing, to create a set of turtle graphics commands.
For simplicity, there are no routines provided for viewport, scale, transform, rotate, or pushing or popping transformation matrices.
2. rsTurtle module
The rsTurtle module contains the turtle class that subclasses the canvas class in the rsCanvas module.
The various methods of the turtle class are now presented and discussed.
3. Initializer
The initializer calls the super class
canvas and then sets some instance variables.
The pen is down when penDown1 is 1, else it is 0.
The angle of the turtle is angle1 in degrees.
The list of coordinates to be drawn is in the list polyList1.
4. Up
5. Down
6. Absolute turn
7. Relative turn
8. Move
9. Draw
The draw method draws the current points, if needed.
10. rsTurtle module
Here is a code module in Python [module rsTurtle in rsTurtle.py].
11. Fractal routine
Here is a fractal routine to draw a Koch coastline.
12. Degrees
Here is the code to draw 6 levels of Koch coastline.
13. Setup code
Here is the setup code.
The stub is set in the main code.
14. Program
Here is the Python code [#12]
15. Output
Here is the output of the Python code.
16. Image #1
17. Image #2
18. Image #3
19. Image #4
20. Image #5
21. Image #6
22. End of page