Commit ea13d9d8 authored by Alexander Belopolsky's avatar Alexander Belopolsky

Issue #10199: Moved Demo/turtle under Lib/

parent 8291af23
#!/usr/bin/env python3
""" turtle-example-suite:
tdemo-I_dont_like_tiltdemo.py
Demostrates
(a) use of a tilted ellipse as
turtle shape
(b) stamping that shape
We can remove it, if you don't like it.
Without using reset() ;-)
---------------------------------------
"""
from turtle import *
import time
def main():
reset()
shape("circle")
resizemode("user")
pu(); bk(24*18/6.283); rt(90); pd()
tilt(45)
pu()
turtlesize(16,10,5)
color("red", "violet")
for i in range(18):
fd(24)
lt(20)
stamp()
color("red", "")
for i in range(18):
fd(24)
lt(20)
stamp()
tilt(-15)
turtlesize(3, 1, 4)
color("blue", "yellow")
for i in range(17):
fd(24)
lt(20)
if i%2 == 0:
stamp()
time.sleep(1)
while undobufferentries():
undo()
ht()
write("OK, OVER!", align="center", font=("Courier", 18, "bold"))
return "Done!"
if __name__=="__main__":
msg = main()
print(msg)
# mainloop()
#!/usr/bin/env python3
""" turtle-example-suite:
xtx_lindenmayer_indian.py
Each morning women in Tamil Nadu, in southern
India, place designs, created by using rice
flour and known as kolam on the thresholds of
their homes.
These can be described by Lindenmayer systems,
which can easily be implemented with turtle
graphics and Python.
Two examples are shown here:
(1) the snake kolam
(2) anklets of Krishna
Taken from Marcia Ascher: Mathematics
Elsewhere, An Exploration of Ideas Across
Cultures
"""
################################
# Mini Lindenmayer tool
###############################
from turtle import *
def replace( seq, replacementRules, n ):
for i in range(n):
newseq = ""
for element in seq:
newseq = newseq + replacementRules.get(element,element)
seq = newseq
return seq
def draw( commands, rules ):
for b in commands:
try:
rules[b]()
except TypeError:
try:
draw(rules[b], rules)
except:
pass
def main():
################################
# Example 1: Snake kolam
################################
def r():
right(45)
def l():
left(45)
def f():
forward(7.5)
snake_rules = {"-":r, "+":l, "f":f, "b":"f+f+f--f--f+f+f"}
snake_replacementRules = {"b": "b+f+b--f--b+f+b"}
snake_start = "b--f--b--f"
drawing = replace(snake_start, snake_replacementRules, 3)
reset()
speed(3)
tracer(1,0)
ht()
up()
backward(195)
down()
draw(drawing, snake_rules)
from time import sleep
sleep(3)
################################
# Example 2: Anklets of Krishna
################################
def A():
color("red")
circle(10,90)
def B():
from math import sqrt
color("black")
l = 5/sqrt(2)
forward(l)
circle(l, 270)
forward(l)
def F():
color("green")
forward(10)
krishna_rules = {"a":A, "b":B, "f":F}
krishna_replacementRules = {"a" : "afbfa", "b" : "afbfbfbfa" }
krishna_start = "fbfbfbfb"
reset()
speed(0)
tracer(3,0)
ht()
left(45)
drawing = replace(krishna_start, krishna_replacementRules, 3)
draw(drawing, krishna_rules)
tracer(1)
return "Done!"
if __name__=='__main__':
msg = main()
print(msg)
mainloop()
This diff is collapsed.
......@@ -2266,29 +2266,36 @@ not from within the demo-viewer).
Demo scripts
============
There is a set of demo scripts in the turtledemo directory located in the
:file:`Demo/turtle` directory in the source distribution.
There is a set of demo scripts in the :mod:`turtledemo` package. These
scripts can be run and viewed using the supplied demo viewer as follows::
It contains:
python -m turtledemo
Alternatively, you can run the demo scripts individually. For example,
::
python -m turtledemo.bytedesign
The :mod:`turtledemo` package directory contains:
- a set of 15 demo scripts demonstrating different features of the new module
:mod:`turtle`
- a demo viewer :file:`turtleDemo.py` which can be used to view the sourcecode
:mod:`turtle`;
- a demo viewer :file:`__main__.py` which can be used to view the sourcecode
of the scripts and run them at the same time. 14 of the examples can be
accessed via the Examples menu; all of them can also be run standalone.
- The example :file:`turtledemo_two_canvases.py` demonstrates the simultaneous
- The example :mod:`turtledemo.two_canvases` demonstrates the simultaneous
use of two canvases with the turtle module. Therefore it only can be run
standalone.
- There is a :file:`turtle.cfg` file in this directory, which also serves as an
- There is a :file:`turtle.cfg` file in this directory, which serves as an
example for how to write and use such files.
The demoscripts are:
The demo scripts are:
+----------------+------------------------------+-----------------------+
| Name | Description | Features |
+----------------+------------------------------+-----------------------+
| bytedesign | complex classical | :func:`tracer`, delay,|
| | turtlegraphics pattern | :func:`update` |
| | turtle graphics pattern | :func:`update` |
+----------------+------------------------------+-----------------------+
| chaos | graphs verhust dynamics, | world coordinates |
| | proves that you must not | |
......
......@@ -329,11 +329,19 @@ class DictTest(unittest.TestCase):
k, v = 'abc', 'def'
d[k] = v
self.assertRaises(KeyError, d.pop, 'ghi')
try:
d.pop('ghi')
except KeyError as e:
self.assertEquals(e.args[0], 'ghi')
self.assertEqual(d.pop(k), v)
self.assertEqual(len(d), 0)
self.assertRaises(KeyError, d.pop, k)
try:
d.pop(k)
except KeyError as e:
self.assertEquals(e.args[0], k)
self.assertEqual(d.pop(k, v), v)
d[k] = v
......
......@@ -44,9 +44,9 @@ for t in p,q:
## Want to get some info?
print(s1, s2)
print(p, q)
print(s1.turtles())
print(s2.turtles())
#print(s1, s2)
#print(p, q)
#print(s1.turtles())
#print(s2.turtles())
TK.mainloop()
......@@ -893,6 +893,7 @@ LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \
importlib/test/extension importlib/test/frozen \
importlib/test/import_ importlib/test/source \
setuptools setuptools/command setuptools/tests setuptools.egg-info \
turtledemo \
multiprocessing multiprocessing/dummy \
unittest unittest/test \
curses pydoc_data $(MACHDEPS)
......
......@@ -59,6 +59,9 @@ Core and Builtins
Library
-------
- Issue #10199: New package, ``turtledemo`` now contains selected demo
scripts that were formerly found under Demo/turtle.
- Issue #10265: Close file objects explicitly in sunau. Patch by Brian Brazil.
- Issue #10266: uu.decode didn't close in_file explicitly when it was given
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment