Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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
Example #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)
Example #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)
Example #10
0
def polyline(t, n, length, angle):
    for i in range(n):
        fd(t, length)
        lt(t, angle)
Example #11
0
def fdlt(t, n, angle=90):
    """forward and left"""
    fd(t, n)
    lt(t, angle)
Example #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)
Example #13
0
def draw_i(t, n):
    beam(t, n, 2)
    fd(t, n/2)
    post(t, 2*n)
    fd(t, n/2)
Example #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()

Example #15
0
def draw_l(t, n):
    post(t, 2*n)
    fd(t, n)
Example #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)
Example #17
0
def draw_square(turtle_name, length):
    for i in range(4):
        fd(turtle_name, length)
        lt(turtle_name)
Example #18
0
def draw_e(t, n):
    draw_ef(t, n)
    fd(t, n)
Example #19
0
def draw_z(t, n):
    beam(t, n, 2)
    diagonal(t, n, 2*n)
    fd(t, n)
Example #20
0
def skip(t, n):
    """lift the pen and move"""
    pu(t)
    fd(t, n)
    pd(t)
Example #21
0
def draw_u(t, n):
    post(t, 2*n)
    fd(t, n)
    post(t, 2*n)
Example #22
0
def square(t,steps):
    for i in range(4):
        fd(t, steps)
        lt(t)
Example #23
0
def draw_square(turtle_name, length):
    for i in range(4):
        fd(turtle_name, length)
        lt(turtle_name)
Example #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)
Example #25
0
def fdbk(t, n):
    """forward and back, ending at the original position"""
    fd(t, n)
    bk(t, n)
Example #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)
Example #27
0
def draw_c(t, n):
    hangman(t, n, 2)
    fd(t, n)