~flimm/python-snippets/gtkcrashhandler

« back to all changes in this revision

Viewing changes to pyturtle/tdemo_yinyang.py

  • Committer: Jono Bacon
  • Date: 2010-04-24 18:14:20 UTC
  • mfrom: (93.3.2 python-snippets-bzr)
  • Revision ID: jono@system76-pc-20100424181420-hup208wuekhvr1qc
A bunch of PyTurtle snippets. Thanks, Grant!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# [SNIPPET_NAME: Yin Yang]
 
4
# [SNIPPET_CATEGORIES: PyTurtle]
 
5
# [SNIPPET_DESCRIPTION: Use turtle to draw a yin yang.]
 
6
# [SNIPPET_DOCS: http://docs.python.org/library/turtle.html]
 
7
# [SNIPPET_AUTHOR: Grant Bowman <grantbow@ubuntu.com>]
 
8
# [SNIPPET_LICENSE: PSF]
 
9
# Code authorship from http://python.org/download/releases/2.6.4/
 
10
 
 
11
 
 
12
"""       turtle-example-suite:
 
13
 
 
14
            tdemo_yinyang.py
 
15
 
 
16
Another drawing suitable as a beginner's
 
17
programming example.
 
18
 
 
19
The small circles are drawn by the circle
 
20
command.
 
21
 
 
22
"""
 
23
 
 
24
from turtle import *
 
25
 
 
26
def yin(radius, color1, color2):
 
27
    width(3)
 
28
    color("black")
 
29
    fill(True)
 
30
    circle(radius/2., 180)
 
31
    circle(radius, 180)
 
32
    left(180)
 
33
    circle(-radius/2., 180)
 
34
    color(color1)
 
35
    fill(True)
 
36
    color(color2)
 
37
    left(90)
 
38
    up()
 
39
    forward(radius*0.375)
 
40
    right(90)
 
41
    down()
 
42
    circle(radius*0.125)
 
43
    left(90)
 
44
    fill(False)
 
45
    up()
 
46
    backward(radius*0.375)
 
47
    down()
 
48
    left(90)
 
49
 
 
50
def main():
 
51
    reset()
 
52
    yin(200, "white", "black")
 
53
    yin(200, "black", "white")
 
54
    ht()
 
55
    return "Done!"
 
56
 
 
57
if __name__ == '__main__':
 
58
    main()
 
59
    mainloop()