def prepare(self, mcmap):
        '''Initialize the internal values for the Tree object.

        Primarily, sets up the foliage cluster locations.
        '''
        treeposition = self.pos
        self.trunkradius = .618 * sqrt(self.height * TRUNKTHICKNESS)
        if self.trunkradius < 1:
            self.trunkradius = 1
        if BROKENTRUNK:
            self.trunkheight = self.height * (.3 + random() * .4)
            yend = int(treeposition[1] + self.trunkheight + .5)
        else:
            self.trunkheight = self.height
            yend = int(treeposition[1] + self.height)
        self.branchdensity = BRANCHDENSITY / FOLIAGEDENSITY
        topy = treeposition[1] + int(self.trunkheight + 0.5)
        foliage_coords = []
        ystart = treeposition[1]
        num_of_clusters_per_y = int(1.5 + (FOLIAGEDENSITY *
                                           self.height / 19.) ** 2)
        if num_of_clusters_per_y < 1:
            num_of_clusters_per_y = 1
        # make sure we don't spend too much time off the top of the map
        if yend > 255:
            yend = 255
        if ystart > 255:
            ystart = 255
        for y in range(yend, ystart, -1):
            for i in range(num_of_clusters_per_y):
                shapefac = self.shapefunc(y - ystart)
                if shapefac is None:
                    continue
                r = (sqrt(random()) + .328) * shapefac

                theta = random() * 2 * pi
                x = int(r * sin(theta)) + treeposition[0]
                z = int(r * cos(theta)) + treeposition[2]
                # if there are values to search in STOPSBRANCHES
                # then check to see if this cluster is blocked
                # by stuff, like dirt or rock, or whatever
                if len(STOPSBRANCHES):
                    dist = (sqrt(float(x - treeposition[0]) ** 2 +
                                 float(z - treeposition[2]) ** 2))
                    slope = self.branchslope
                    if y - dist * slope > topy:
                        # the top of the tree
                        starty = topy
                    else:
                        starty = y - dist * slope
                    # the start position of the search
                    start = [treeposition[0], starty, treeposition[2]]
                    offset = [x - treeposition[0],
                              y - starty,
                              z - treeposition[2]]
                    offlength = sqrt(offset[0] ** 2 + offset[1] ** 2 + offset[2] ** 2)
                    # if the branch is as short as... nothing, don't bother.
                    if offlength < 1:
                        continue
                    # unit vector for the search
                    vec = [offset[i] / offlength for i in range(3)]
                    mat_dist = dist_to_mat(start, vec, STOPSBRANCHES,
                                           mcmap, limit=offlength + 3)
                    # after all that, if you find something, don't add
                    # this coordinate to the list
                    if mat_dist < offlength + 2:
                        continue
                foliage_coords += [[x, y, z]]

        self.foliage_cords = foliage_coords
Initialize the internal values for the Tree object.

        Primarily, sets up the foliage cluster locations.
        
stock-filters/Forester.py