import turtle
import random

def drawFern(pen, depth, length, contraction, branches, firstBranchAngle, nextBranchAngle):
    if depth > 0:
        # remember the pen's heading and location
        heading = pen.heading()
        position = pen.position()
        # Draw a branch
        pen.width(depth) # branch width is directly proportional to depth
        pen.forward(length)
        pen.left(firstBranchAngle)
        for i in range(branches):
            pen.width(depth-1)
            drawFern(pen, depth-1, contraction*length, contraction, branches, firstBranchAngle, nextBranchAngle)
            pen.right(nextBranchAngle)

        # restore pen to its start heading and location
        pen.setheading(heading)
        pen.setposition(position)

def drawForest(numOfTrees, xcoord, ycoord):
    while numOfTrees > 0:
        # creates starting location for first tree (within certain bounds)
        p.setx(xcoord)
        p.sety(ycoord)
        p.down()
        drawFern(p, 6, 120, 0.7, 5, 40, 15)
        # re-randomizes the x and y coordinates for a new tree
        xcoord = random.randint(-450,450)
        ycoord = random.randint(-350,-150)
        numOfTrees-=1
        p.up()

p = turtle.Pen() # creates a turtle
p.tracer(False) # this draws faster by not following the turtle animation
p.left(90) # point him up
p.up()

# sets bounds on the turtle's grid for where trees can be drawn
xcoord = random.randint(-450,450)
ycoord = random.randint(-350,-150)

drawForest(20, xcoord, ycoord) # command to draw a forest through functions

p.tracer(True)
turtle.exitonclick()


e9c563988ff507bf10697f80da4f290c30bafe1f
<mask token>


def drawFern(pen, depth, length, contraction, branches, firstBranchAngle,
    nextBranchAngle):
    if depth > 0:
        heading = pen.heading()
        position = pen.position()
        pen.width(depth)
        pen.forward(length)
        pen.left(firstBranchAngle)
        for i in range(branches):
            pen.width(depth - 1)
            drawFern(pen, depth - 1, contraction * length, contraction,
                branches, firstBranchAngle, nextBranchAngle)
            pen.right(nextBranchAngle)
        pen.setheading(heading)
        pen.setposition(position)


def drawForest(numOfTrees, xcoord, ycoord):
    while numOfTrees > 0:
        p.setx(xcoord)
        p.sety(ycoord)
        p.down()
        drawFern(p, 6, 120, 0.7, 5, 40, 15)
        xcoord = random.randint(-450, 450)
        ycoord = random.randint(-350, -150)
        numOfTrees -= 1
        p.up()


<mask token>

<mask token>


def drawFern(pen, depth, length, contraction, branches, firstBranchAngle,
    nextBranchAngle):
    if depth > 0:
        heading = pen.heading()
        position = pen.position()
        pen.width(depth)
        pen.forward(length)
        pen.left(firstBranchAngle)
        for i in range(branches):
            pen.width(depth - 1)
            drawFern(pen, depth - 1, contraction * length, contraction,
                branches, firstBranchAngle, nextBranchAngle)
            pen.right(nextBranchAngle)
        pen.setheading(heading)
        pen.setposition(position)


def drawForest(numOfTrees, xcoord, ycoord):
    while numOfTrees > 0:
        p.setx(xcoord)
        p.sety(ycoord)
        p.down()
        drawFern(p, 6, 120, 0.7, 5, 40, 15)
        xcoord = random.randint(-450, 450)
        ycoord = random.randint(-350, -150)
        numOfTrees -= 1
        p.up()


<mask token>
p.tracer(False)
p.left(90)
p.up()
<mask token>
drawForest(20, xcoord, ycoord)
p.tracer(True)
turtle.exitonclick()

<mask token>


def drawFern(pen, depth, length, contraction, branches, firstBranchAngle,
    nextBranchAngle):
    if depth > 0:
        heading = pen.heading()
        position = pen.position()
        pen.width(depth)
        pen.forward(length)
        pen.left(firstBranchAngle)
        for i in range(branches):
            pen.width(depth - 1)
            drawFern(pen, depth - 1, contraction * length, contraction,
                branches, firstBranchAngle, nextBranchAngle)
            pen.right(nextBranchAngle)
        pen.setheading(heading)
        pen.setposition(position)


def drawForest(numOfTrees, xcoord, ycoord):
    while numOfTrees > 0:
        p.setx(xcoord)
        p.sety(ycoord)
        p.down()
        drawFern(p, 6, 120, 0.7, 5, 40, 15)
        xcoord = random.randint(-450, 450)
        ycoord = random.randint(-350, -150)
        numOfTrees -= 1
        p.up()


p = turtle.Pen()
p.tracer(False)
p.left(90)
p.up()
xcoord = random.randint(-450, 450)
ycoord = random.randint(-350, -150)
drawForest(20, xcoord, ycoord)
p.tracer(True)
turtle.exitonclick()

import turtle
import random


def drawFern(pen, depth, length, contraction, branches, firstBranchAngle,
    nextBranchAngle):
    if depth > 0:
        heading = pen.heading()
        position = pen.position()
        pen.width(depth)
        pen.forward(length)
        pen.left(firstBranchAngle)
        for i in range(branches):
            pen.width(depth - 1)
            drawFern(pen, depth - 1, contraction * length, contraction,
                branches, firstBranchAngle, nextBranchAngle)
            pen.right(nextBranchAngle)
        pen.setheading(heading)
        pen.setposition(position)


def drawForest(numOfTrees, xcoord, ycoord):
    while numOfTrees > 0:
        p.setx(xcoord)
        p.sety(ycoord)
        p.down()
        drawFern(p, 6, 120, 0.7, 5, 40, 15)
        xcoord = random.randint(-450, 450)
        ycoord = random.randint(-350, -150)
        numOfTrees -= 1
        p.up()


p = turtle.Pen()
p.tracer(False)
p.left(90)
p.up()
xcoord = random.randint(-450, 450)
ycoord = random.randint(-350, -150)
drawForest(20, xcoord, ycoord)
p.tracer(True)
turtle.exitonclick()

import turtle
import random

def drawFern(pen, depth, length, contraction, branches, firstBranchAngle, nextBranchAngle):
    if depth > 0:
        # remember the pen's heading and location
        heading = pen.heading()
        position = pen.position()
        # Draw a branch
        pen.width(depth) # branch width is directly proportional to depth
        pen.forward(length)
        pen.left(firstBranchAngle)
        for i in range(branches):
            pen.width(depth-1)
            drawFern(pen, depth-1, contraction*length, contraction, branches, firstBranchAngle, nextBranchAngle)
            pen.right(nextBranchAngle)

        # restore pen to its start heading and location
        pen.setheading(heading)
        pen.setposition(position)

def drawForest(numOfTrees, xcoord, ycoord):
    while numOfTrees > 0:
        # creates starting location for first tree (within certain bounds)
        p.setx(xcoord)
        p.sety(ycoord)
        p.down()
        drawFern(p, 6, 120, 0.7, 5, 40, 15)
        # re-randomizes the x and y coordinates for a new tree
        xcoord = random.randint(-450,450)
        ycoord = random.randint(-350,-150)
        numOfTrees-=1
        p.up()

p = turtle.Pen() # creates a turtle
p.tracer(False) # this draws faster by not following the turtle animation
p.left(90) # point him up
p.up()

# sets bounds on the turtle's grid for where trees can be drawn
xcoord = random.randint(-450,450)
ycoord = random.randint(-350,-150)

drawForest(20, xcoord, ycoord) # command to draw a forest through functions

p.tracer(True)
turtle.exitonclick()

