Ejemplo n.º 1
0
def draw_j(t, n):
    beam(t, n, 2)
    arc(t, n/2, 90)
    fd(t, 3*n/2)
    skip(t, -2*n)
    rt(t)
    skip(t, n/2)
Ejemplo n.º 2
0
def draw_s(t, n):
    fd(t, n/2)
    arc(t, n/2, 180)
    arc(t, n/2, -180)
    fdlt(t, n/2, -90)
    skip(t, 2*n)
    lt(t)
Ejemplo n.º 3
0
def move(t, length):
    """Move Turtle (t) forward (length) units without leaving a trail.
    Leaves the pen down.
    """
    pu(t)
    fd(t, length)
    pd(t)
Ejemplo n.º 4
0
def square(t, length):
    """Draws a square with sides of the given length.

    Returns the Turtle to the starting position and location.
    """
    for i in range(4):
        fd(t, length)
        lt(t)
Ejemplo n.º 5
0
def polyline(t, n, length, angle):
    """Draws n line segments.

    t: Turtle object
    n: number of line segments
    length: length of each segment
    angle: degrees between segments
    """
    for i in range(n):
        fd(t, length)
        lt(t, angle)
Ejemplo n.º 6
0
def draw_pie(t, n, r):
    """Draws a pie, then moves into position to the right.

    t: Turtle
    n: number of segments
    r: length of the radial spokes
    """
    polypie(t, n, r)
    pu(t)
    fd(t, r*2 + 10)
    pd(t)
Ejemplo n.º 7
0
def draw_spiral(t, n, length=3, a=0.1, b=0.0002):
    """Draws an Archimedian spiral starting at the origin.

    Args:
      n: how many line segments to draw
      length: how long each segment is
      a: how loose the initial spiral starts out (larger is looser)
      b: how loosly coiled the spiral is (larger is looser)

    http://en.wikipedia.org/wiki/Spiral
    """
    theta = 0.0

    for i in range(n):
        fd(t, length)
        dtheta = 1 / (a + b * theta)

        lt(t, dtheta)
        theta += dtheta
Ejemplo n.º 8
0
def pie(t, sides, radius):
  angle1 = 360.0 / sides
  angle2 = (180.0 - angle1) / 2
  print angle1
  print angle2
  rt(t, angle1 / 2)

  for _ in range(sides):
    fd(t, radius)
    lt(t, 180 - angle2)
    fd(t, 2 * radius * sin(pi / 180 * angle1 / 2))
    lt(t, 180 - angle2)
    fd(t, radius)
    rt(t, 180)
Ejemplo n.º 9
0
def isosceles(t, r, angle):
    """Draws an icosceles triangle.

    The turtle starts and ends at the peak, facing the middle of the base.

    t: Turtle
    r: length of the equal legs
    angle: peak angle in degrees
    """
    y = r * math.sin(angle * math.pi / 180)

    rt(t, angle)
    fd(t, r)
    lt(t, 90+angle)
    fd(t, 2*y)
    lt(t, 90+angle)
    fd(t, r)
    lt(t, 180-angle)
Ejemplo n.º 10
0
def polyline(t, n, length, angle):
    for i in range(n):
        fd(t, length)
        lt(t, angle)
Ejemplo n.º 11
0
def fdlt(t, n, angle=90):
    """forward and left"""
    fd(t, n)
    lt(t, angle)
Ejemplo n.º 12
0
def draw_g(t, n):
    hangman(t, n, 2)
    fd(t, n/2)
    beam(t, n/2, 2)
    fd(t, n/2)
    post(t, n)
Ejemplo n.º 13
0
def draw_i(t, n):
    beam(t, n, 2)
    fd(t, n/2)
    post(t, 2*n)
    fd(t, n/2)
Ejemplo n.º 14
0
def circle(t, r):
    """Draws a circle with the given radius.

    t: Turtle
    r: radius
    """
    arc(t, r, 360)


# the following condition checks whether we are
# running as a script, in which case run the test code,
# or being imported, in which case don't.

if __name__ == '__main__':
    world = TurtleWorld()    

    bob = Turtle()
    bob.delay = 0.001

    # draw a circle centered on the origin
    radius = 100
    pu(bob)
    fd(bob, radius)
    lt(bob)
    pd(bob)
    circle(bob, radius)
    die(bob)
    wait_for_user()

Ejemplo n.º 15
0
def draw_l(t, n):
    post(t, 2*n)
    fd(t, n)
Ejemplo n.º 16
0
def draw_polygon(turtle_name, length, num_sides):
    degree = 360 / num_sides

    for i in range(num_sides):
        fd(turtle_name, length)
        lt(turtle_name, degree)
Ejemplo n.º 17
0
def draw_square(turtle_name, length):
    for i in range(4):
        fd(turtle_name, length)
        lt(turtle_name)
Ejemplo n.º 18
0
def draw_e(t, n):
    draw_ef(t, n)
    fd(t, n)
Ejemplo n.º 19
0
def draw_z(t, n):
    beam(t, n, 2)
    diagonal(t, n, 2*n)
    fd(t, n)
Ejemplo n.º 20
0
def skip(t, n):
    """lift the pen and move"""
    pu(t)
    fd(t, n)
    pd(t)
Ejemplo n.º 21
0
def draw_u(t, n):
    post(t, 2*n)
    fd(t, n)
    post(t, 2*n)
Ejemplo n.º 22
0
def square(t,steps):
    for i in range(4):
        fd(t, steps)
        lt(t)
Ejemplo n.º 23
0
def draw_square(turtle_name, length):
    for i in range(4):
        fd(turtle_name, length)
        lt(turtle_name)
Ejemplo n.º 24
0
def stump(t, n, angle=90):
    """make a vertical line and leave the turtle at the top, facing right"""
    lt(t)
    fd(t, n)
    rt(t, angle)
Ejemplo n.º 25
0
def fdbk(t, n):
    """forward and back, ending at the original position"""
    fd(t, n)
    bk(t, n)
Ejemplo n.º 26
0
def draw_polygon(turtle_name, length, num_sides):
    degree = 360 / num_sides

    for i in range(num_sides):
        fd(turtle_name, length)
        lt(turtle_name, degree)
Ejemplo n.º 27
0
def draw_c(t, n):
    hangman(t, n, 2)
    fd(t, n)