File: distance.py

package info (click to toggle)
pythoncard 0.8.1-8.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,352 kB
  • ctags: 4,594
  • sloc: python: 42,401; makefile: 55; sh: 22
file content (36 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

import math
from wrappers import Turtle

def draw(canvas):
    t1 = Turtle(canvas)
    t1.cls()

    """
    # test towards (towardsXY)
    # these kinds of tests should be done using pyunit
    tt = Turtle(canvas)
    for i in range(0, 370, 10):
        tt.pu()
        tt.lt(i)
        tt.fd(100)
        print "angle: %f, t1 towards tt: %f, tt towards t1: %f" % (i, t1.towards(tt), tt.towards(t1))
        tt.bk(100)
        tt.rt(i)
    """

    # test the distance calculation
    t1.left(45)
    t1.forward(100 * math.sqrt(2))

    t2 = Turtle(canvas)
    t2.forward(100)
    d = t2.distance(t1)
    # should display 100
    t2.write("%f" % d)

    # test the odometer reading
    t1.resetOdometer()
    t1.resumeOdometer()
    t1.polygon(4, 100)
    t1.write("odometer: %f" % t1.getOdometer())